Search code examples
rakeprocess-managementsimultaneous

How to make sure only one rake task is running at a time?


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?


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.