rails class note reminders code example

Example 1: rails class note reminders

ReminderJob = Struct.new(:event) do def enqueue(job)   job.delayable = event   job.save! end def perform   event.send_reminder end def queue_name   'reminder_queue' endend

Example 2: rails class note reminders

after_save :new_reminder def new_reminder   Delayed::Job.enqueue(ReminderJob.new(self), { run_at: self.when_to_run }) end def send_reminder   # Send a text message reminder 2 hours before event start   @client = Twilio::REST::Client.new(Rails.application.credentials.twilio_account_sid, Rails.application.credentials.twilio_auth_token)   @client.messages.create({     from: "Name",     to: "phone number",     body: "Message to the user"     }) end def when_to_run   minutes_before_appointment = 120.minutes   self.starts_at - minutes_before_appointment end

Tags:

Misc Example