使用Rufus Scheduler 2.x在启动时运行cron [英] Running a cron on start-up using Rufus Scheduler 2.x

查看:120
本文介绍了使用Rufus Scheduler 2.x在启动时运行cron的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在启动时运行cron,然后每天从此开始午夜.

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

我被Dashing约束使用Rufus Scheduler 2.0.24,在其中我不能在cron命令中使用"first_in".我要复制的3.x版本中的命令就像这样...

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?

我发现描述了类似的问题-但这只会在指定的分配时间的第一个实例上运行cron,而不会立即运行.

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.

推荐答案

一种简单的方法是:

job =
  proc do
    puts "hello"
  end

job.call
  # run it right now

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

但是也许这更易读:

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

job.block.call
  # run it right now

scheduler.join

感谢您发布新问题,一切都变得清晰起来. Rufus Scheduler:cron未知的first_in选项中的问题是有点不同.

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.

我知道这是关于rufus-scheduler 2.0.24的,但是我想指出3.3.x中的一项新功能:

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.

回到2.0.24,上面显示的快捷方式没有改进,它将立即运行该块.该块可能已经有一个实例正在运行,假设您已将时间表设置为每晚午夜",而您恰巧在午夜重新启动.因此,我认为上面的第一个解决方案是最好的,因为它会触发然后进行调度.

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.

这篇关于使用Rufus Scheduler 2.x在启动时运行cron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆