feat(infra): add scheduler and worker-generate standalone processes
Extract monitoring recovery/inspection workers and schedule dispatch into a dedicated scheduler process. Add worker-generate process for article generation and template-assist queue consumption. Introduce shared/schedule runtime for cron-based worker lifecycle management. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/bootstrap"
|
||||
tenantapp "github.com/geo-platform/tenant-api/internal/tenant/app"
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/repository"
|
||||
generateworker "github.com/geo-platform/tenant-api/internal/worker/generate"
|
||||
)
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
templateSvc := tenantapp.NewTemplateService(
|
||||
app.DB,
|
||||
repository.NewCachedTemplateRepository(
|
||||
repository.NewTemplateRepository(app.DB),
|
||||
app.Cache,
|
||||
),
|
||||
app.LLM,
|
||||
nil,
|
||||
knowledgeSvc,
|
||||
app.GenerationStreams,
|
||||
generationCfg,
|
||||
app.Config.LLM.MaxOutputTokens,
|
||||
)
|
||||
|
||||
promptRuleSvc := tenantapp.NewPromptRuleGenerationService(
|
||||
app.DB,
|
||||
app.LLM,
|
||||
nil,
|
||||
knowledgeSvc,
|
||||
app.GenerationStreams,
|
||||
generationCfg,
|
||||
app.Config.LLM.MaxOutputTokens,
|
||||
)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
generateworker.NewArticleGenerationWorker(
|
||||
app.DB,
|
||||
app.RabbitMQ,
|
||||
templateSvc,
|
||||
promptRuleSvc,
|
||||
app.Logger,
|
||||
app.Config.Generation,
|
||||
).Start(ctx)
|
||||
|
||||
generateworker.NewTemplateAssistWorker(
|
||||
app.RabbitMQ,
|
||||
templateSvc,
|
||||
app.Logger,
|
||||
app.Config.Generation.WorkerConcurrency,
|
||||
app.Config.Generation.ArticleTimeout,
|
||||
).Start(ctx)
|
||||
|
||||
app.Logger.Info("worker-generate started")
|
||||
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-quit
|
||||
cancel()
|
||||
app.Logger.Info("worker-generate shutting down...")
|
||||
}
|
||||
Reference in New Issue
Block a user