This commit is contained in:
Tomas Dvorak
2026-01-26 08:13:18 +01:00
parent aa036b6550
commit dfc079288f
505 changed files with 95755 additions and 5712 deletions
+13 -3
View File
@@ -148,12 +148,22 @@ func (na *NewsletterAutomation) checkWeeklyDigest() {
currentDay := strings.ToLower(now.Weekday().String()[:3])
currentHour := now.Hour()
// Check if it's the right day and hour
if currentDay != targetDay || currentHour != targetHour {
// Check if it's the right day and hour (with minute precision to prevent multiple sends)
currentMinute := now.Minute()
if currentDay != targetDay || currentHour != targetHour || currentMinute > 5 {
// Only run in the first 5 minutes of the target hour to avoid repeats
return
}
// Check if already sent today
// Check if already sent today (using database for persistence)
var todaySent models.NewsletterSentLog
todayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
if err := na.db.Where("newsletter_type = ? AND sent_at >= ?", "weekly", todayStart).First(&todaySent).Error; err == nil {
log.Printf("[newsletter-automation] Weekly digest already sent today at %s", todaySent.SentAt.Format("15:04:05"))
return
}
// Also check in-memory as backup
if na.lastWeekly.Year() == now.Year() && na.lastWeekly.YearDay() == now.YearDay() {
return
}