Running a cron on start-up using Rufus Scheduler 2

2019-08-02 18:16发布

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条回答
可以哭但决不认输i
2楼-- · 2019-08-02 18:58

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.

查看更多
登录 后发表回答