2026-04-01 00:58:42 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2026-04-12 09:56:18 +08:00
|
|
|
"context"
|
2026-04-01 00:58:42 +08:00
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
|
|
"github.com/geo-platform/tenant-api/internal/bootstrap"
|
2026-04-12 09:56:18 +08:00
|
|
|
tenantapp "github.com/geo-platform/tenant-api/internal/tenant/app"
|
2026-04-01 00:58:42 +08:00
|
|
|
"github.com/geo-platform/tenant-api/internal/tenant/transport"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
2026-04-12 09:56:18 +08:00
|
|
|
workerCtx, workerCancel := context.WithCancel(context.Background())
|
|
|
|
|
defer workerCancel()
|
|
|
|
|
|
2026-05-01 16:01:23 +08:00
|
|
|
app.StartConfigWatcher(workerCtx)
|
|
|
|
|
|
2026-04-15 14:19:57 +08:00
|
|
|
app.GenerationStreams.Run(workerCtx)
|
2026-04-19 14:18:20 +08:00
|
|
|
app.DesktopTaskStreams.Run(workerCtx)
|
2026-04-20 19:46:59 +08:00
|
|
|
app.DesktopDispatch.Run(workerCtx)
|
2026-04-15 14:19:57 +08:00
|
|
|
|
2026-05-01 16:01:23 +08:00
|
|
|
monitoringService := app.MonitoringService
|
2026-04-12 09:56:18 +08:00
|
|
|
monitoringCallbackService := tenantapp.NewMonitoringCallbackService(app.DB, app.MonitoringDB, app.RabbitMQ, app.LLM, app.Logger)
|
2026-04-22 00:24:21 +08:00
|
|
|
tenantapp.NewMonitoringCollectOutboxWorker(monitoringService, app.Logger).Start(workerCtx)
|
2026-05-01 16:01:23 +08:00
|
|
|
tenantapp.NewMonitoringResultIngestWorker(monitoringCallbackService, app.RabbitMQ, app.Logger, app.Config().MonitoringWorkers).Start(workerCtx)
|
|
|
|
|
tenantapp.NewMonitoringProjectionRebuildWorker(monitoringCallbackService, app.RabbitMQ, app.Logger, app.Config().MonitoringWorkers).Start(workerCtx)
|
2026-04-27 21:33:36 +08:00
|
|
|
tenantapp.NewDesktopAccountHealthSinkWorker(app.DB, app.RabbitMQ, app.Logger).Start(workerCtx)
|
2026-04-16 20:40:41 +08:00
|
|
|
imageService := tenantapp.NewImageService(app.DB, app.ObjectStorage, app.RabbitMQ, app.Logger)
|
|
|
|
|
tenantapp.NewImageAssetWorker(imageService, app.RabbitMQ, app.Logger).Start(workerCtx)
|
2026-05-20 11:22:37 +08:00
|
|
|
knowledgeCleanupService := tenantapp.NewKnowledgeService(
|
|
|
|
|
app.DB,
|
|
|
|
|
app.RetrievalProvider,
|
|
|
|
|
app.VectorStore,
|
|
|
|
|
app.ObjectStorage,
|
|
|
|
|
app.LLM,
|
|
|
|
|
app.Logger,
|
|
|
|
|
app.Config().Retrieval,
|
|
|
|
|
app.Config().LLM,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
).WithConfigProvider(app.ConfigStore)
|
|
|
|
|
tenantapp.NewKnowledgeDeletedCleanupEventWorker(knowledgeCleanupService, app.Logger).Start(workerCtx)
|
2026-04-12 09:56:18 +08:00
|
|
|
|
2026-04-01 00:58:42 +08:00
|
|
|
transport.RegisterRoutes(app)
|
|
|
|
|
|
2026-05-01 16:01:23 +08:00
|
|
|
addr := fmt.Sprintf(":%d", app.Config().Server.Port)
|
2026-04-01 00:58:42 +08:00
|
|
|
app.Logger.Sugar().Infof("tenant-api starting on %s", addr)
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
if err := app.Engine.Run(addr); err != nil {
|
|
|
|
|
app.Logger.Sugar().Fatalf("server: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
quit := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
<-quit
|
2026-04-12 09:56:18 +08:00
|
|
|
workerCancel()
|
2026-04-01 00:58:42 +08:00
|
|
|
app.Logger.Info("shutting down...")
|
|
|
|
|
}
|