Files
tg-holy-bot/internal/holy/cronTask.go
2026-03-21 12:14:26 +03:00

61 lines
964 B
Go

package holy
import (
"tg-holy-bot/internal/log"
"time"
)
// CronTask sends generated holiday list to the channel.
func CronTask() {
var (
err error
errcnt int
phrase string
timeout time.Duration
)
log.Info("Cron Task triggered")
for {
phrase, err = APIClient()
if err != nil {
errcnt++
log.Errorf("Unable to get holidays (try %d/15): %s", errcnt, err)
switch errcnt {
case 0, 1, 2:
timeout = 1 * time.Second
case 3, 4, 5:
timeout = 5 * time.Second
case 6, 7, 8:
timeout = 1 * time.Minute
case 9, 10, 11:
timeout = 5 * time.Minute
case 12, 13, 14:
timeout = 1 * time.Hour
default:
log.Error("Giveup trying to get holidays")
return
}
} else {
break
}
time.Sleep(timeout)
}
if _, err = Bot.SendMessage(phrase, Config.ChannelID, nil); err != nil {
log.Errorf("Unable to send message to channel: %s", err)
}
}
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */