touch up redeliver loop
This commit is contained in:
parent
73fb03845b
commit
2518c4be4a
|
@ -47,8 +47,8 @@ func sayitagain(goarounds int64, userid int64, rcpt string, msg []byte) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
drift += time.Duration(notrand.Int63n(int64(drift / 10)))
|
drift += time.Duration(notrand.Int63n(int64(drift / 10)))
|
||||||
when := time.Now().UTC().Add(drift)
|
when := time.Now().Add(drift)
|
||||||
_, err := stmtAddDoover.Exec(when.Format(dbtimeformat), goarounds, userid, rcpt, msg)
|
_, err := stmtAddDoover.Exec(when.UTC().Format(dbtimeformat), goarounds, userid, rcpt, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
elog.Printf("error saving doover: %s", err)
|
elog.Printf("error saving doover: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ func getdoovers() []Doover {
|
||||||
}
|
}
|
||||||
|
|
||||||
func redeliverator() {
|
func redeliverator() {
|
||||||
sleeper := time.NewTimer(0)
|
sleeper := time.NewTimer(5 * time.Second)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-pokechan:
|
case <-pokechan:
|
||||||
|
@ -144,7 +144,7 @@ func redeliverator() {
|
||||||
|
|
||||||
doovers := getdoovers()
|
doovers := getdoovers()
|
||||||
|
|
||||||
now := time.Now().UTC()
|
now := time.Now()
|
||||||
nexttime := now.Add(24 * time.Hour)
|
nexttime := now.Add(24 * time.Hour)
|
||||||
for _, d := range doovers {
|
for _, d := range doovers {
|
||||||
if d.When.Before(now) {
|
if d.When.Before(now) {
|
||||||
|
@ -168,7 +168,11 @@ func redeliverator() {
|
||||||
nexttime = d.When
|
nexttime = d.When
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dur := nexttime.Sub(now).Round(time.Second) + 5*time.Second
|
now = time.Now()
|
||||||
|
dur := 5 * time.Second
|
||||||
|
if now.Before(nexttime) {
|
||||||
|
dur += nexttime.Sub(now).Round(time.Second)
|
||||||
|
}
|
||||||
sleeper.Reset(dur)
|
sleeper.Reset(dur)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue