Skip to content

Commit

Permalink
reminder: Reduce poll rate
Browse files Browse the repository at this point in the history
  • Loading branch information
godwhoa committed Dec 6, 2018
1 parent 24aa1f5 commit aa51471
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions plugins/core/reminder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type RemindIn struct {
mailbox *MailBox
}

const pollrate = 6 * time.Hour

func (r *RemindIn) send(reminder Reminder) {
if !r.checker.InChannel(reminder.By) {
r.mailbox.Send(Letter{
Expand All @@ -44,11 +46,19 @@ func (r *RemindIn) fn(nick string, args []string) (string, error) {
return err.Error(), nil
}
msg := strings.Join(args[1:], " ")
r.store.Set(Reminder{
reminder := Reminder{
By: nick,
Msg: msg,
At: time.Now().Add(duration),
})
}
if duration < pollrate {
go func() {
time.Sleep(duration)
r.send(reminder)
}()
return "Reminder set!", nil
}
r.store.Set(reminder)
return "Reminder set!", nil
}

Expand All @@ -66,7 +76,7 @@ func (r *RemindIn) sendout() {
func (r *RemindIn) Watch() {
for {
r.sendout()
time.Sleep(1 * time.Second)
time.Sleep(pollrate)
}
}

Expand Down

0 comments on commit aa51471

Please sign in to comment.