我需要一个cron表达式才能在工作日正好5:30 am
执行一些代码。
我尝试过这个
30 5 * * 1-5
但它在晚上10:30执行 在互联网上搜索,我找到了这个
0 30 5 ? * MON,TUE,WED,THU,FRI *
但是ruby给我显示一条异常消息,说:
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.5.2/lib/rufus/scheduler/jobs.rb:674:in `next_time_from': undefined method `next_time' for nil:NilClass (NoMethodError)
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.5.2/lib/rufus/scheduler/jobs.rb:668:in `set_next_time'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.5.2/lib/rufus/scheduler/jobs.rb:636:in `initialize'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.5.2/lib/rufus/scheduler.rb:617:in `new'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.5.2/lib/rufus/scheduler.rb:617:in `do_schedule'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.5.2/lib/rufus/scheduler.rb:224:in `cron'
from E:/Marcos_Guerra/RubyWorkspace/calisoft-suite/Proyectos/RedmineApi/api.rb:30:in `<main>'
这是我的代码:
ENV['TZ'] = 'America/New_York'
scheduler = Rufus::Scheduler.new
scheduler.cron '0 30 5 ? * MON,TUE,WED,THU,FRI *' do
begin
# do something that might fail...
# every day of the week at 05:30 am
puts RedmineConnector.resetYourLife(user,pass)
rescue => e
end
end
sleep 3
我正在使用Rufus Gem
答案 0 :(得分:0)
According to the project README,您可以按以下时区指定cron作业:
scheduler.cron '30 5 * * 1-5 America/New_York' do
# ...
end
这 的意思是“如您所愿,在工作日正好5:30”。