Enhance worker configuration and error handling for AI summarizer
continuous-integration/drone/push Build is passing

- Added `TranslationEnabled` and `TranslationInterval` fields to the worker configuration to manage automatic translation scheduling.
- Updated the worker initialization to log when the translation worker is disabled.
- Improved error handling in the AI summarizer client by introducing `APIStatusError` for better context on API failures, replacing direct error messages with structured error responses.

This update enhances the configurability of the worker and improves error reporting for AI service interactions, contributing to better maintainability and user experience.
This commit is contained in:
Mazyar
2026-06-14 14:02:35 +03:30
parent 42d64c4ec6
commit ca35eb5f15
5 changed files with 89 additions and 22 deletions
+7 -1
View File
@@ -85,6 +85,8 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
"notice_processing_limit": config.Worker.NoticeProcessingLimit,
"notice_batch_pause": config.Worker.NoticeBatchPause.String(),
"notice_fetch_error_backoff": config.Worker.NoticeFetchErrorBackoff.String(),
"translation_enabled": config.Worker.TranslationEnabled,
"translation_interval": config.Worker.TranslationInterval,
})
// Initialize repositories
noticeRepo := notice.NewRepository(mongoManager, appLogger)
@@ -138,7 +140,11 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
})
// Initialize translation backfill worker for configured languages
if aiClient != nil {
if !config.Worker.TranslationEnabled {
appLogger.Info("Tender translation worker disabled by configuration", map[string]interface{}{
"translation_enabled": false,
})
} else if aiClient != nil {
targetLanguages := parseTranslationLanguages(config.AISummarizer)
translationSuccessCounter := mongo.NewCounter(mongoManager)
scheduler.AddJob(schedule.Job{
+3
View File
@@ -30,6 +30,9 @@ type WorkerConfig struct {
NoticeFetchErrorBackoff time.Duration `env:"WORKER_NOTICE_FETCH_ERROR_BACKOFF" envDefault:"2s"`
TranslationInterval string `env:"WORKER_TRANSLATION_INTERVAL" envDefault:"0 */30 * * * *"`
TranslationBatchSize int `env:"WORKER_TRANSLATION_BATCH_SIZE" envDefault:"20"`
// TranslationEnabled schedules the automatic batch translation cron job on the worker.
// On-demand translation (admin/public tender endpoints and AI pipeline routes on web) is unaffected.
TranslationEnabled bool `env:"WORKER_TRANSLATION_ENABLED" envDefault:"true"`
}
// AISummarizerConfig holds configuration for the external AI summarizer service.