0e4fadaf29
continuous-integration/drone/push Build is passing
- Updated the company service to include a new method for scheduling the refresh of cached AI recommendations after the AI pipeline execution. - Introduced a new interface for managing cached recommendation refreshes, improving the separation of concerns within the service layer. - Enhanced the worker initialization to include Redis client support, allowing for better management of recommendation caching. - Added functionality to list company IDs with existing recommendation caches, ensuring efficient updates post-pipeline runs. - Implemented unit tests to validate the new recommendation refresh logic and ensure proper handling of various scenarios. This update significantly improves the handling of AI recommendations by integrating caching mechanisms with the AI pipeline, enhancing overall system performance and responsiveness.
72 lines
2.0 KiB
Go
72 lines
2.0 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 AI summarizer client (translation worker)
|
|
aiSummarizerClient := bootstrap.InitAISummarizerClient(config.AISummarizer, mongoManager, appLogger)
|
|
aiSummarizerStorage := bootstrap.InitAISummarizerStorage(config.AISummarizer, appLogger)
|
|
redisClient := bootstrap.InitRedis(config.Redis, appLogger)
|
|
defer func() {
|
|
if redisClient != nil {
|
|
if err := redisClient.Close(); err != nil {
|
|
appLogger.Error("Failed to close Redis connection", map[string]interface{}{
|
|
"error": err.Error(),
|
|
})
|
|
}
|
|
}
|
|
}()
|
|
|
|
// Initialize Worker
|
|
scheduler := bootstrap.InitWorker(*config, mongoManager, appLogger, notificationService, aiSummarizerClient, aiSummarizerStorage, redisClient)
|
|
|
|
// 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{}{})
|
|
}
|