Running a cron on start-up using Rufus Scheduler 2.x

拜拜、爱过 提交于 2020-01-24 19:46:07

问题


I'm trying to run a cron on start-up and then midnight every day from that point.

I'm bound by Dashing to use Rufus Scheduler 2.0.24, in which I can't use 'first_in' with the cron command. The command in 3.x I want to replicate is like so...

scheduler.cron '00 00 * * *', :first_in => '0' do

I'm wondering if there is any way around this?

I found this which describes a similar issue - but this will only run the cron at the first instance of the specified allotted time and not immediately.


回答1:


a plain way of doing it would be:

job =
  proc do
    puts "hello"
  end

job.call
  # run it right now

scheduler.cron('00 00 * * *', &job)

But maybe this one is more readable:

job =
  scheduler.cron '00 00 * * *' do
    puts 'hello'
  end

job.block.call
  # run it right now

scheduler.join

Thanks for posting a new question, it made everything clear. The question at Rufus Scheduler :first_in option unknown with cron is a bit different.

I know this is about rufus-scheduler 2.0.24, but I'd like to point to a new feature in 3.3.x: https://github.com/jmettraux/rufus-scheduler/issues/214 where you can do job.trigger_off_schedule and it invokes the job right now if overlap, mutex and other job options allow it.

Back to 2.0.24, the shortcut shown above has no refinement, it will run the block right now. The block might already have an instance running now, imagine you have the schedule set for "midnight every night" and you happen to restart at midnight. Hence, I think the first solution above, is best, because it triggers then schedules.



来源:https://stackoverflow.com/questions/41302466/running-a-cron-on-start-up-using-rufus-scheduler-2-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!