RailsCasts - Ruby on Rails Screencasts

RailsCasts Pro episodes are now free!

Learn more or hide this

Cron in Ruby (revised)

#164 Cron in Ruby (revised)

Dec 29, 2011 | 6 minutes | Tools, Plugins, Deployment, Background Jobs
Cron is a common solution for recurring jobs, but it has a confusing syntax. In this episode I show you how to use Whenever to create cron jobs using Ruby. Some alternative scheduling solutions are also mentioned.
Click to Play Video ▶
Tweet
  • Download:
  • source code Project Files in Zip (78.3 KB)
  • mp4 Full Size H.264 Video (20.1 MB)
  • m4v Smaller H.264 Video (9.84 MB)
  • webm Full Size VP8 Video (7.52 MB)
  • ogv Full Size Theora Video (27 MB)
Browse_code Browse Source Code

Resources

terminal
bundle
bundle exec wheneverize
bundle exec whenever
Gemfile
gem 'whenever', require: false
config/schedule.rb
set :output, "#{path}/log/cron.log"
job_type :script, "'#{path}/script/:task' :output"
every 15.minutes do
 command "rm '#{path}/tmp/cache/foo.txt'"
 script "generate_report"
end
every :sunday, at: "4:28 AM" do
 runner "Cart.clear_abandoned"
end
every :reboot do
 rake "ts:start"
end
config/deploy.rb
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
loading

AltStyle によって変換されたページ (->オリジナル) /