1

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
4

1 に答える 1

0

新しいスレッドでスケジュールを生成する必要がありますか?

いいえ、rufus-scheduler が代わりに行います。

作成するスケジュールごとに新しいスケジューラ インスタンスを作成する必要がありますか?

いいえ、まったくありません。

頻度を設定せずに (rufus-scheduler のデフォルトの頻度を使用して) 試しましたか?

rufus-scheduler の問題は発生していませんが、以下をお読みください: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

あなたの環境についての詳細を提供していません。あなたを助けることは非常に困難です。

小さいものから大きいものへと繰り返してみてください。小さなスケジュールで仕事をしてから、一歩ずつ進んでください。

于 2013-07-11T08:12:30.567 に答える