使用Rufus-Scheduler事件设置更多Rufus-Scheduler事件

时间:2013-07-09 21:58:38

标签: ruby rufus-scheduler

我有一个脚本,我尝试使用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

1 个答案:

答案 0 :(得分:0)

  

我是否需要在新线程上生成计划?

不,rufus-scheduler会为你做这件事。

  

我是否需要为我要创建的每个计划创建一个新的调度程序实例?

不,完全没有。

您是否尝试过不设置频率(使用rufus-scheduler的默认频率)?

虽然您没有遇到rufus-scheduler问题,但请阅读:http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

您没有提供有关您的环境的任何细节,很难帮助您。

尝试从小到大迭代。做一个小计划的东西工作,然后继续前进一步。

相关问题