Last active
October 25, 2020 15:25
-
-
Save hchood/096adcfa9e673e33e52e579dd89af0ee to your computer and use it in GitHub Desktop.
dj.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assumes Reminder has attribute `send_at` | |
# 1. When Reminder is created, schedule first job in after create hook | |
# 2. Each time the job is run, schedule a new one for the next day (or whenever) | |
class Reminder < ApplicationRecord | |
after_create :schedule_first_job # use Rails after_create callback to call the `schedule` method after the record is created | |
def schedule_first_job | |
schedule_next_job(send_at) # or whenever you next want it to run | |
end | |
def schedule_next_job(schedule_at) | |
send_sms | |
schedule_next_job(schedule_at + 1.day) | |
end | |
def send_sms | |
# tell Twilio to send SMS w/ given text | |
end | |
handle_asynchronously :schedule_next_job, run_at: Proc.new { schedule_at } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment