Files
geo/server/cmd/scheduler/main.go
T
root 1538a12042 feat(cache): add read-through cache layer across all app services
Introduce a generic read-through caching infrastructure and wire it into
all major tenant app services to reduce database load on hot read paths.

Key changes:
- Add `DeletePrefix` to Cache interface with memory (prefix scan) and
  Redis (SCAN + DEL) implementations
- New `readthrough.go`: generic `LoadJSON` / `LoadJSONWithEmpty` helpers
  backed by singleflight to prevent cache stampedes; supports jittered TTL
- New `cache_support.go`: centralized cache key builders and invalidation
  helpers for all entities (workspace, brand, prompt rules, schedule tasks,
  articles)
- Wire optional cache into ArticleService, BrandService, WorkspaceService,
  PromptRuleService, ScheduleTaskService, TemplateService, MediaService,
  PromptGenerateService via `WithCache()` builder pattern
- ScheduleDispatchWorker invalidates schedule task cache after dispatching
- ArticleService gains a new `Detail` endpoint with empty-result caching
- Update cmd entrypoints and transport handlers to propagate cache
2026-04-15 16:11:05 +08:00

78 lines
1.9 KiB
Go

package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"github.com/geo-platform/tenant-api/internal/bootstrap"
internalscheduler "github.com/geo-platform/tenant-api/internal/scheduler"
tenantapp "github.com/geo-platform/tenant-api/internal/tenant/app"
)
func main() {
configPath := "configs/config.yaml"
if p := os.Getenv("CONFIG_PATH"); p != "" {
configPath = p
}
app, err := bootstrap.New(configPath)
if err != nil {
log.Fatalf("bootstrap: %v", err)
}
defer app.Close()
generationCfg := app.Config.Generation
generationCfg.StreamEnabled = false
knowledgeSvc := tenantapp.NewKnowledgeService(
app.DB,
app.RetrievalProvider,
app.VectorStore,
app.ObjectStorage,
app.LLM,
app.Logger,
app.Config.Retrieval,
app.Config.LLM,
0,
0,
)
promptRuleSvc := tenantapp.NewPromptRuleGenerationService(
app.DB,
app.LLM,
app.RabbitMQ,
knowledgeSvc,
app.GenerationStreams,
generationCfg,
app.Config.LLM.MaxOutputTokens,
).WithCache(app.Cache)
monitoringCallbackService := tenantapp.NewMonitoringCallbackService(
app.DB,
app.MonitoringDB,
app.RabbitMQ,
app.LLM,
app.Logger,
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
internalscheduler.NewScheduleDispatchWorker(app.DB, app.RabbitMQ, promptRuleSvc, app.Cache, app.Logger, app.Config.Scheduler).Start(ctx)
internalscheduler.NewMonitoringResultRecoveryWorker(app.MonitoringDB, monitoringCallbackService, app.Logger).Start(ctx)
internalscheduler.NewMonitoringLeaseRecoveryWorker(app.MonitoringDB, app.Logger).Start(ctx)
internalscheduler.NewMonitoringReceivedInspectionWorker(app.MonitoringDB, app.Logger).Start(ctx)
internalscheduler.NewKnowledgeDeletedCleanupWorker(knowledgeSvc).Start(ctx)
app.Logger.Info("scheduler started")
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
cancel()
app.Logger.Info("scheduler shutting down...")
}