68b170126d
- Updated `InitAISummarizerClient` to accept `mongoManager` for tracking translation success. - Introduced new `Statistics` endpoint in the dashboard to fetch scraping and translation statistics. - Enhanced `TranslationWorker` to utilize the new success counter for tracking successful translations. - Added necessary data structures and query forms for statistics reporting. This refactor improves the tracking of AI translation success and provides new insights through the dashboard statistics.
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
"tm/cmd/worker/bootstrap"
|
|
)
|
|
|
|
func main() {
|
|
// Load configuration
|
|
config, err := bootstrap.InitConfig()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Initialize logger
|
|
appLogger := bootstrap.InitLogger(config.Logging)
|
|
appLogger.Info("Starting worker application", map[string]interface{}{
|
|
"version": "1.0.0",
|
|
})
|
|
|
|
// Initialize MongoDB connection
|
|
mongoManager := bootstrap.InitMongoDB(config.Database.MongoDB, appLogger)
|
|
defer func() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
if err := mongoManager.Close(ctx); err != nil {
|
|
appLogger.Error("Failed to close MongoDB connection", map[string]interface{}{
|
|
"error": err.Error(),
|
|
})
|
|
}
|
|
}()
|
|
|
|
// Initialize notification service
|
|
notificationService := bootstrap.InitNotificationService(config.Notification, appLogger)
|
|
|
|
// Initialize MinIO service
|
|
minioService := bootstrap.InitMinIOService(config.MinIO, appLogger)
|
|
if minioService != nil {
|
|
appLogger.Info("MinIO service initialized successfully", map[string]interface{}{})
|
|
}
|
|
|
|
// Initialize AI summarizer client (translation + document summarization workers)
|
|
aiSummarizerClient := bootstrap.InitAISummarizerClient(config.AISummarizer, mongoManager, appLogger)
|
|
aiSummarizerStorage := bootstrap.InitAISummarizerStorage(config.AISummarizer, appLogger)
|
|
|
|
// Initialize Worker
|
|
scheduler := bootstrap.InitWorker(*config, mongoManager, appLogger, notificationService, minioService, aiSummarizerClient, aiSummarizerStorage)
|
|
|
|
// Set up signal handling for graceful shutdown
|
|
signalChan := make(chan os.Signal, 1)
|
|
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
// Wait for shutdown signal
|
|
<-signalChan
|
|
appLogger.Info("Received shutdown signal, stopping scheduler...", map[string]interface{}{})
|
|
|
|
// Stop scheduler gracefully
|
|
if scheduler != nil {
|
|
scheduler.Stop()
|
|
}
|
|
|
|
appLogger.Info("Worker application stopped", map[string]interface{}{})
|
|
}
|