Created
May 7, 2011 15:03
-
-
Save shedd/960566 to your computer and use it in GitHub Desktop.
Lockrun support for Whenever cron jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Support running Whenever cron jobs with Lockrun | |
# Lockrun: http://www.unixwiz.net/tools/lockrun.html | |
# lockrun typically installed at /usr/bin/lockrun | |
# On Mac, install with: brew install lockrun | |
# Lockrun prefix for cronjobs: /usr/bin/lockrun --lockfile=/path/to/tmp/JOBNAME.lockrun -- sh -c "COMMAND" | |
def wrap_with_lockrun command | |
"/usr/bin/env lockrun --lockfile=:path/tmp/:lockfile.lockrun -- sh -c \"#{ command }\"" | |
end | |
#redefine the three default job types to use Lockrun (i.e. just add 'lockrun_' in front of the existing job names) | |
# and add the :lockfile => "LOCKFILENAME" option to specify what to call the lockfile | |
job_type :lockrun_command, wrap_with_lockrun(":task :output") | |
job_type :lockrun_rake, wrap_with_lockrun("cd :path && RAILS_ENV=:environment rake :task :output") | |
job_type :lockrun_runner, wrap_with_lockrun("cd :path && script/runner -e :environment ':task' :output") | |
# So, this is a sample job setup to run with lockrun: | |
# every 1.day, :at => '2:37am' do | |
# lockrun_command "testcommand", :lockfile => "LOCKFILENAME" | |
# end | |
# this is the output: | |
# 37 2 * * * /bin/bash -l -c '/usr/bin/env lockrun --lockfile=/path/to/tmp/LOCKFILENAME.lockrun -- sh -c "testcommand "' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These custom job types are setup to work with the Whenever gem: https://github.com/javan/whenever