package holy import ( "tg-holy-bot/internal/log" "time" ) const maxRetryAttempts = 15 // 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/%d): %s", errcnt, maxRetryAttempts, err) switch errcnt { case 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: */