mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-05 03:02:56 +00:00
hot fix #1
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user