Skip to content

Instantly share code, notes, and snippets.

@hchood
Last active October 25, 2020 15:25
Show Gist options
  • Save hchood/096adcfa9e673e33e52e579dd89af0ee to your computer and use it in GitHub Desktop.
Save hchood/096adcfa9e673e33e52e579dd89af0ee to your computer and use it in GitHub Desktop.
dj.rb
# 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