我有一个脚本,我尝试使用Rufus-Scheduler在凌晨1点创建每日计划(基于日出和日落)。当我运行代码时,它似乎只运行第一个调度程序事件,而不会运行它之后的任何事件。我的理解是Rufus-Scheduler应该为每个调度产生一个新的线程,但它看起来像是阻塞了。我需要在一个新的线程上产生调度吗?我是否需要为要创建的每个计划创建一个新的计划程序实例?我在代码的底部添加了一个测试调度器,但它没有被创建。
以下是与rufus-scheduler相关的代码部分
def get_todays_show()
this_year = Time.now.year
check_sunset
#the time format that comes back isn't reconginzed by rufus scheduler so recreate it with chronic
sunrise = Chronic.parse("#{@local_sunrise.to_s[0,10]} #{@local_sunrise.to_s[11,8]}" )
sunset = Chronic.parse("#{@local_sunset.to_s[0,10]} #{@local_sunset.to_s[11,8]}" )
schedule_array = create_array_from_csv
schedule_array.each do |sub_array|
earlier = Chronic.parse("#{sub_array[0]} #{this_year} 12:00:01 am")
later = Chronic.parse("#{sub_array[1]} #{this_year} 11:59:59")
range = earlier..later
if range.cover?(Time.now)
@scheduler.at sunset do
madrix_call(sub_array[2].strip)
end
@scheduler.at sunrise do
madrix_call(@off_slot)
end
end
end
end
#set up the scheduler
@scheduler = Rufus::Scheduler.start_new(:frequency => 30.0)
#run it once to handle today
get_todays_show
#the schedule to handle the future
@scheduler.cron '1 1 * * *' do
get_todays_show
p @scheduler.jobs
end
@scheduler.cron '* * * * *' do
p "test schedule - #{Time.now}"
end
@scheduler.join发布于 2013-07-11 16:12:31
我是否需要在一个新线程上派生调度?
不,rufus-scheduler是为你做的。
我是否需要为要创建的每个计划创建一个新的计划程序实例?
没关系,您请。
您是否在没有设置频率的情况下尝试过(使用rufus-scheduler的默认频率)?
尽管您没有遇到rufus调度器问题,但请阅读:http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
你没有提供任何关于你的环境的细节,很难帮助你。
尝试从小到大迭代。制定一个小的时间表,然后一步接着一步地进行。
https://stackoverflow.com/questions/17559009
复制相似问题