+// TelegramOutage is one run of failures of a kind of Bot API call. The first
+// failure logs loss, its cause, and the wait of the next try. The retries log
+// nothing. The next answer of Telegram logs back and the length of the outage.
+// loss and back say what the user loses and gets again.
+type TelegramOutage struct {
+ logger *log.Logger
+ loss string
+ back string
+ start time.Time
+}
+
+// Fail logs the start of an outage with err and delay, unless an outage runs.
+func (o *TelegramOutage) Fail(err error, delay time.Duration) {
+ if !o.start.IsZero() {
+ return
+ }
+
+ o.start = time.Now()
+ o.logger.Printf("%s: %v (next try in %s)", o.loss, err, durationText(delay))
+}
+
+// End logs the end of the outage that runs, with its length.
+func (o *TelegramOutage) End() {
+ if o.start.IsZero() {
+ return
+ }
+
+ o.logger.Printf("%s, after %s", o.back, durationText(time.Since(o.start)))
+ o.start = time.Time{}
+}
+