Files
tm_back/cmd/worker/main.go
T
n.nakhostin 0747908873 Add AlertMail Configuration and Enhance TED Scraper Notification Logic
- Introduced AlertMail configuration in both scraper and worker bootstrap files, allowing for customizable email notifications.
- Updated the TED scraper to utilize the AlertMail configuration for sending completion notifications, improving flexibility in notification management.
- Enhanced error logging in the worker's main function to capture issues when listing Ollama models, ensuring better visibility into potential failures.
- Refactored notification sending logic to check for a valid AlertMail before dispatching emails, ensuring notifications are only sent when configured.
- Improved overall structure and readability of the bootstrap configuration files, aligning with best practices for maintainability.
2025-10-16 16:20:23 +03:30

63 lines
1.7 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 ollama service
ollamaSDK := bootstrap.InitOllamaService(config.Ollama, appLogger)
aiModels, err := ollamaSDK.ListModels(context.Background())
if err != nil {
appLogger.Error("Failed to list ollama models", map[string]interface{}{
"error": err.Error(),
})
}
appLogger.Info("Ollama models", map[string]interface{}{"models": aiModels})
// Initialize Worker
bootstrap.InitWorker(*config, mongoManager, appLogger, notificationService, ollamaSDK)
// 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{}{})
appLogger.Info("Worker application stopped", map[string]interface{}{})
}