Back

rufu-scheduler 的at, 只能用Time 格式 (only use a specific time format in rufu scheduler's at)

发布时间: 2013-09-27 09:07:00

如题。 下面是个例子:

# -*- encoding : utf-8 -*-
ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'production'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'rubygems'
require 'rufus/scheduler'
require 'rails'
require 'time'
scheduler = Rufus::Scheduler.start_new
scheduler.at Time.parse('2013-09-27 23:30:00') do
#scheduler.in '1s' do
CmsTvSubject.find(63).update_attributes(:state => 1)
Rails.logger.info " == job done"
end
scheduler.at Time.parse('2013-09-29 23:30:00') do
CmsTvSubject.find(64).update_attributes(:state => 1)
end
scheduler.at Time.parse('2013-09-30 23:30:00') do
CmsTvSubject.find(65).update_attributes(:state => 1)
end
scheduler.at Time.parse('2013-10-2 23:30:00') do
CmsTvSubject.find(66).update_attributes(:state => 1)
end
scheduler.at Time.parse('2013-10-4 23:30:00') do
CmsTvSubject.find(67).update_attributes(:state => 1)
end
scheduler.at Time.parse('2013-10-6 23:30:00') do
CmsTvSubject.find(68).update_attributes(:state => 1)
end
scheduler.join

Back