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.
This commit is contained in:
+24
-20
@@ -27,6 +27,7 @@ type Config struct {
|
||||
RetryDelay time.Duration `mapstructure:"retry_delay"`
|
||||
CleanupAfter time.Duration `mapstructure:"cleanup_after"`
|
||||
ScrapingInterval string `mapstructure:"scraping_interval"`
|
||||
AlertMail string `mapstructure:"ALERT_MAIL"`
|
||||
}
|
||||
|
||||
// TEDScraper handles downloading and parsing TED XML files
|
||||
@@ -251,26 +252,29 @@ func (s *TEDScraper) tarGzFileProcessor(ctx context.Context, reader io.Reader, o
|
||||
}
|
||||
}
|
||||
|
||||
go s.notify.SendNotification(
|
||||
context.Background(),
|
||||
¬ification.NotificationRequest{
|
||||
EventType: notification.EventTypeEmail,
|
||||
Title: "TED scraper completed",
|
||||
Message: GenerateFileProcessingEmailTemplate(
|
||||
&FileProcessingEmailTemplateData{
|
||||
OJS: ojs,
|
||||
ProcessedCount: result.ProcessedCount,
|
||||
SuccessCount: result.SuccessCount,
|
||||
Errors: result.Errors,
|
||||
ProcessedAt: result.ProcessedAt,
|
||||
}),
|
||||
Priority: "important",
|
||||
Methods: notification.NotificationMethods{
|
||||
Email: "nakhostin.nima1998@gmail.com",
|
||||
},
|
||||
UserID: "ted-scraper",
|
||||
Type: "alert",
|
||||
})
|
||||
if s.config.AlertMail != "" {
|
||||
|
||||
go s.notify.SendNotification(
|
||||
context.Background(),
|
||||
¬ification.NotificationRequest{
|
||||
EventType: notification.EventTypeEmail,
|
||||
Title: "TED scraper completed",
|
||||
Message: GenerateFileProcessingEmailTemplate(
|
||||
&FileProcessingEmailTemplateData{
|
||||
OJS: ojs,
|
||||
ProcessedCount: result.ProcessedCount,
|
||||
SuccessCount: result.SuccessCount,
|
||||
Errors: result.Errors,
|
||||
ProcessedAt: result.ProcessedAt,
|
||||
}),
|
||||
Priority: "important",
|
||||
Methods: notification.NotificationMethods{
|
||||
Email: s.config.AlertMail,
|
||||
},
|
||||
UserID: "ted-scraper",
|
||||
Type: "alert",
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user