refine the redeliver timeout schedule
Ted Unangst tedu@tedunangst.com
Tue, 13 Jun 2023 13:42:15 -0400
1 files changed,
10 insertions(+),
16 deletions(-)
jump to
M
deliverator.go
→
deliverator.go
@@ -35,28 +35,22 @@ Msgs [][]byte
} func sayitagain(doover Doover) { - rcpt := doover.Rcpt - var drift time.Duration doover.Tries += 1 - switch doover.Tries { - case 1: - drift = 5 * time.Minute - case 2: - drift = 1 * time.Hour - case 3: - drift = 4 * time.Hour - case 4: - drift = 12 * time.Hour - case 5: - drift = 24 * time.Hour - default: - ilog.Printf("he's dead jim: %s", rcpt) + var drift time.Duration + if doover.Tries <= 3 { // 5, 10, 15 minutes + drift = time.Duration(doover.Tries*5) * time.Minute + } else if doover.Tries <= 6 { // 1, 2, 3 hours + drift = time.Duration(doover.Tries-3) * time.Hour + } else if doover.Tries <= 9 { // 12, 12, 12 hours + drift = time.Duration(12) * time.Hour + } else { + ilog.Printf("he's dead jim: %s", doover.Rcpt) return } drift += time.Duration(notrand.Int63n(int64(drift / 10))) when := time.Now().Add(drift) data := bytes.Join(doover.Msgs, []byte{0}) - _, err := stmtAddDoover.Exec(when.UTC().Format(dbtimeformat), doover.Tries, doover.Userid, rcpt, data) + _, err := stmtAddDoover.Exec(when.UTC().Format(dbtimeformat), doover.Tries, doover.Userid, doover.Rcpt, data) if err != nil { elog.Printf("error saving doover: %s", err) }