Sending SMS from rails app

| | August 5, 2015

I am building a medication reminder system using Ruby on Rails to be deployed on heroku.

Using this system a doctor will enter a patient’s medication details including medication name, dose as well as timing details and the app will then notify the patient via sms when its time to take his/her medicine.

I have developed the application but I am stuck on the sms part since that involves running a process over and over again until the medication’s period has elapsed.

I want to be able to run a script from a rails app that will repeatedly query the database and when it is time to send a sms it will dispatch it to the patient. This cannot function in the normal request/response web cycle.

I explored rubygems that allow developers to create background jobs such as rufus scheduler and resque but I can’t seem to figure out how to go about doing this.

Please help I am open to all types of suggestions. I am using Twilio for sending sms

3 Responses to “Sending SMS from rails app”

  1. I use delayed_job using the run_at param to send scheduled SMS via Twilio from Heroku.

    I have a send_message method on my message model that does the actual send with the Twilio API. I chose to create a custom job with Delayed Job so when I schedule the message:

    Delayed::Job.enqueue my_custom_job, :run_at => TIME_I_WANT_TO_SEND
    

    Using a the heroku worker to run the background task of sending has been very reliable.

  2. Since you’re deploying to Heroku, reading their documentation about scheduling jobs is a must for you:

    https://devcenter.heroku.com/articles/scheduler

  3. Philip Hallstrom on November 30, -0001 @ 12:00 AM

    I don’t know about resque/rufus, but I know that sidekiq has the ability to queue jobs, but have them delayed till a certain time.

    https://github.com/mperham/sidekiq/wiki/Delayed-Extensions#advanced-options

    You’d need to look into how exact the delay is (ie. what sidekiq’s polling frequency is) depending on your needs, but I would suspect this would work well.

    It would require another dynamo or whatever heroku calls it these days.

Leave a Reply