You can use a lock file for this. When the task is running, try to capture the lock and run the rake task if you get a lock. If you do not get a lock, then do not use rake; you may need to file an error or warning somewhere too, or you can finish your rake task without doing anything for weeks or months before you find out. When the rake comes out, open the lock file.
Something like RAA might help, but I haven't used it, maybe not.
You can also use the PID file. You will have a file somewhere that contains the rake process process id. Before starting the rake, you read the PID from this file and see if this process works; if he does not start the rake and writes his PID to the PID file. When rake exists, delete the PID file. You want to combine this with locking in a PID file if you want to be very strict, but it depends on your specific situation.
source share