views:

90

answers:

2

I am plannning to use whenever gem which among other things will also run minutely rake task. If my rake task takes more than a minute then based on the output from whenever gem it seems like the second instance of the rake task will kick-in even though the first one is not quite finished.

Will whenever gem will wait for the miutely task to finish before starting the second one?

If not then what are the workarounds. I believe this question is better served in serverfault still I am putting it here.

A: 

whenever just writes cronjobs, and makes no effort to stop them overrunning themselves. This is the job of the task that is being run.

Use PID files, or file system locks to prevent the task running over the top of itself.

cwninja
A: 

In my scheduled application, I scan the process list looking for other instances of my application running with the same configuration file on the command line - then exit with a logged note if a process is already running with the same configuration file.

That keeps the program from stepping on itself ...

PID files or some type of "locking" file are prone to problems when the process exits but the lock file still exists.

Ron

Ron Savage
There is a difference between a locking file and a file lock (http://apidock.com/ruby/File/flock).
cwninja
Yes, but that doesn't change the logic flaw - you are still testing if the process is running "indirectly" by checking if a file is locked. I check "directly" by scanning the process list, including command line arguments - it's simpler and more flexible.
Ron Savage