Question

I want to setup rake tasks to run via cron. That is easy, but what is not easy is ensuring that only one copy of that rake task is running at a time. I imagine I could use ps on the system to check and then exit the rake task if it is already running, or I could do a delayed job structure where I serialize the name of the task and upon completion I remove it form the DB, but what do you all recommend?

Was it helpful?

Solution

Unix solved this issue with pid files. Pid files are located in /var/run and contain the programs process Id. Here is the man page: http://fuse4bsd.creo.hu/localcgi/man-cgi.cgi?pidfile+3

You might find it a bit old fashioned (and I agree), but it's an often used and proven method.

OTHER TIPS

You can use https://rubygems.org/gems/only_one_rake, like namespace :rails do desc "online user count" only_one_task :online_user_count => :environment do loop { OnlineUser.count; sleep 1 } end end

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top