Try harder to get holidays
This commit is contained in:
@@ -2,19 +2,55 @@ 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")
|
||||
|
||||
phrase, err := APIClient()
|
||||
for {
|
||||
phrase, err = APIClient()
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("Unable to get holidays: %s", err)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user