Search code examples
ruby-on-railsrubyherokudelayed-jobjobs

Which Ruby / Rails Background Job Framework should I use (that works on Heroku) for dynamically adding future jobs in Rails


So I created a client-server (Rails for both client and server) system that will have many clients with one server, that interact using REST.

The clients can send / update / delete their own "Jobs" on the server, which is right now simply a table named Jobs. The Jobs belongs_to a table named Apps, which ofcourse has_many jobs (each App entry represents a client, so the client can only add / delete / update / read their jobs on the server).

The purpose of this, is so the client can add entries to the Jobs table and specify a Time of Day (in the future), that they can run a Job. The Job that gets run is a call to a 3rd party email-service to send an email.

So I need a Jobs framework, that can easily run on Heroku, and iterate through my Jobs table (say, every half-hour.. Or even every 5 minutes maybe..), and see if there are any Jobs it needs to run based on a datetime column (check if the datetime entry is equal-to, or less-than the current-time the Worker is running)

Which is the best Rails / Heroku Job framework I should use for this?

I prefer simplicity, so I was looking at: https://devcenter.heroku.com/articles/scheduler
But, I cannot use this because it warns:

Scheduler is a “best effort” service, meaning that execution is expected but not guaranteed. Scheduler is known to occasionally (but rarely) miss the execution of scheduled jobs"

So next I looked at at https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes - which can be implemented using Gems like Resque or Delayed Job.. Which I am currently researching now..

Ideally, I wanted to be able to find a Job Framework that would compliment (or replace) my jobs table (So, Whenever I add something to my Jobs table or delete it, each of my Job entries would have a 1:1 relation with an actual Job in the Job framework, that I would also be adding / updating / deleting when I add / update / delete an entry on my Jobs table and / or the Jobs entry in the Job Framework). Ofcourse I would be writing the logic for all the CRUD operations on the server (once it receives a REST call from the client) - But the client needs to be able to delete and re-add all it's jobs on the server at any-moment; and I did not see any Job frameworks that would allow me to dynamically add and remove future jobs at any given time, dynamically. All the existing frameworks seem like they are created for scheduled jobs to run at specific times or time intervals, specified in a config file. Which is fine, but I wanted to check on S.O to verify that I am making the best decision when choosing my setup / framework

Sorry for the long / complex question - and I appreciate any suggestions or recommendations anyone has for me!
Thanks!!!


Solution

  • This sounds like a job for Resque and Resque-scheduler.

    Here's a syntax example :

    Resque.enqueue_in(5.days.from_now, SendFollowupEmail, argument)
    

    If you need to delete it before it is executed :

    Resque.remove_delayed(SendFollowUpEmail, :user_id => current_user.id)