Skip to content

Instantly share code, notes, and snippets.

@sdhull
Created April 23, 2011 06:10
Show Gist options
  • Save sdhull/938386 to your computer and use it in GitHub Desktop.
Save sdhull/938386 to your computer and use it in GitHub Desktop.
rake task (including contents of old clock.rb file) to start/stop/restart clockwork.rb
namespace :clockwork do
desc 'Start the clockwork daemon'
task :start => :environment do
pid = fork do
$stdout.reopen("/dev/null")
$stdout.sync = true
$stderr.reopen($stdout)
include Clockwork
handler do |job_class|
Resque.enqueue(job_class)
end
every(30.seconds, Gameday::FrequentUpdates)
every(1.day, Gameday::DailyJob, :at => "01:30")
run
end
Process.detach(pid)
File.open("./tmp/clockwork_#{Rails.env}_pid.txt", "w") do |file|
file << pid
end
end
desc "Stop the clockwork daemon"
task :stop => :environment do
pid = File.read("./tmp/clockwork_#{Rails.env}_pid.txt").to_i
Process.kill(1, pid)
end
desc 'restart the clockwork daemon'
task :restart => [:stop, :start]
end
@sdhull
Copy link
Author

sdhull commented Apr 23, 2011

I really feel like this should come with clockwork.rb somehow.

@philc
Copy link

philc commented Oct 1, 2011

Thanks for the gist!

@sdhull
Copy link
Author

sdhull commented Oct 4, 2011

Glad it was useful for you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment