|
|
@ -40,19 +40,44 @@ type RemindVotersJob struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r *RemindVotersJob) Schedule() {
|
|
|
|
func (r *RemindVotersJob) Schedule() {
|
|
|
|
// TODO: check logic. It would make more sense to remind at a specific interval before the next pending
|
|
|
|
|
|
|
|
// decision is closed
|
|
|
|
|
|
|
|
const reminderDays = 3
|
|
|
|
const reminderDays = 3
|
|
|
|
|
|
|
|
|
|
|
|
year, month, day := time.Now().UTC().Date()
|
|
|
|
now := time.Now().UTC()
|
|
|
|
|
|
|
|
|
|
|
|
nextExecution := time.Date(
|
|
|
|
year, month, day := now.Date()
|
|
|
|
year, month, day, 0, 0, 0, 0, time.UTC,
|
|
|
|
|
|
|
|
).AddDate(0, 0, reminderDays)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r.infoLog.Printf("scheduling RemindVotersJob for %s", nextExecution)
|
|
|
|
nextPotentialRun := time.Date(year, month, day+1, 0, 0, 0, 0, time.UTC)
|
|
|
|
|
|
|
|
nextPotentialRun.Add(hoursInDay * time.Hour)
|
|
|
|
|
|
|
|
|
|
|
|
when := time.Until(nextExecution)
|
|
|
|
relevantDue := nextPotentialRun.Add(reminderDays * hoursInDay * time.Hour)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
due, err := r.decisions.NextPendingDue(context.Background(), relevantDue)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
r.errorLog.Printf("could not fetch next due date: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if due == nil {
|
|
|
|
|
|
|
|
r.infoLog.Printf("no due motions after relevant due date %s, not scheduling ReminderJob", relevantDue)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remindNext := due.Add(-reminderDays * hoursInDay * time.Hour).UTC()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
year, month, day = remindNext.Date()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
potentialRun := time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if potentialRun.Before(time.Now().UTC()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r.infoLog.Printf("potential reminder time %s is in the past, not scheduling ReminderJob", potentialRun)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r.infoLog.Printf("scheduling RemindVotersJob for %s", potentialRun)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when := time.Until(potentialRun)
|
|
|
|
|
|
|
|
|
|
|
|
if r.timer != nil {
|
|
|
|
if r.timer != nil {
|
|
|
|
r.timer.Reset(when)
|
|
|
|
r.timer.Reset(when)
|
|
|
@ -133,7 +158,7 @@ func (c *CloseDecisionsJob) Schedule() {
|
|
|
|
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
|
|
nextDue, err = c.decisions.NextPendingDue(ctx)
|
|
|
|
nextDue, err = c.decisions.NextPendingDue(ctx, time.Now().UTC())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
c.errorLog.Printf("could not get next pending due date")
|
|
|
|
c.errorLog.Printf("could not get next pending due date")
|
|
|
|
|
|
|
|
|
|
|
|