Monday, August 12, 2013

Scheduling tasks in ruby

Recently, I've been trying to run a ruby service on a rails application. As the application was deployed to Heroku, I first consulted the documentation which mentioned delayed_jobs, clockwork and resque.
Delayed jobs approach offers the least surprise in its setup and works using activerecord (It creates a table in your application). However, the least intrusive way is to use clockwork and as I mentioned in my previous post, it only needs a single config file. But if you are looking for fault tolerant systems, there is a need to dig deeper into various other frameworks as well.
Initially I was a bit hesitant to go the Resque way but I found this really handy offshoot that offered scheduling as well as queuing capabilities for various jobs. Resque scheduler is a solution that offers me with these capabilities.

It To view the redis tasks on windows, first we need to have the win32-process gem as well as specify the resque-web not to fork a process as this is not an *nix os.

rescue-web -p 8080 -r localhost:6789 -F -L

Since I required the jobs to requeue, therefore, I added another job that periodically requeued the failures
(Resque::Failure.count-1).downto(0).each{ |i|
Resque::Failure.requeue(i)
}
In execution of the jobs, Sidekiq forms an important alternative to resque as it offers multi-threaded capability to run the queued jobs based on the celluloid .
To summarize, there are various families of background/delayed/queued job schedulers and it is upto the developer to decide which ones to mix and match.
Update: This blog post at github provides information about the efforts made at github.

No comments: