$ gem install whenever
$ cd /project $ wheneverize .
every 30.minutes do runner "Blog.parseAll" end every 30.minutes, :at => 17 do runner "PostWeibo.post" end every 15.minutes do runner "WeiBo.update" end every 30.minutes, :at => 20 do runner "RSSGenerator.generate" end every 1.day, :at => ‘2:00 am‘ do command "cd /var/www/mzread/current/public && gunzip -c sitemap1.xml.gz > sitemap1.xml && touch sitemap1.xml " end
job_type :ruby, "cd :path && /usr/bin/ruby ‘:task‘.rb" every :hour do ruby ‘have_a_rest‘ end
$ whenever #不带参数的whenever会显示转换程cron任务的代码,不写入cron任务表 $ whenever -w #写入cron任务表,开始执行 $ whenever -c #取消任务
$ crontab -l
$ [sudo] gem install sidetiq
class MyWorker include Sidekiq::Worker include Sidetiq::Schedulable recurrence { daily } def perform # do stuff ... end end
require ‘clockwork‘ include Clockwork handler do |job| puts "Running #{job}" end every(10.seconds, ‘frequent.job‘) every(3.minutes, ‘less.frequent.job‘) every(1.hour, ‘hourly.job‘) every(1.day, ‘midnight.job‘, :at => ‘00:00‘)
$ clockwork clock.rb Starting clock for 4 events: [ frequent.job less.frequent.job hourly.job midnight.job ] Triggering frequent.job
require ‘./config/boot‘ require ‘./config/environment‘
原文:http://www.cnblogs.com/wangyuyu/p/3818826.html