← Back to Upcase

Scheduling tasks


(Charlieanna) #1

I want to send a reminder to all the subordinates about the meeting just 30 minutes before the meeting begins. What is the best way to do that?


(Geoff Harcourt) #2

I would set up two background jobs using something like the whenever gem or Heroku scheduler

The first job generates notifications that have to be delivered. That job runs every five minutes or so, and looks for meetings that are less than 30 minutes away. For every meeting that’s within the time frame, it runs through the list of subordinates, and creates a notification per subordinate if one doesn’t already exist.

The second job looks for unsent notifications and delivers them, and then marks them as sent. You want to mark them as sent rather than delete them so that you don’t accidentally generate and deliver notifications more than once for a participant.

This approach might seem overly complicated, but it should be robust to withstand situations where your polling job is delayed in running. If something prevents the job from running 30 minutes before the meeting, you don’t want to just not send an email 25 minutes out instead. Generating the notifications just prior to delivery also enables you to accommodate situations where the subordinates attached to a meeting might change between when the meeting is created and when it is held.