从Rufus调度程序(rails3.2)中cron作业的代码块中确定job_id
-
13-12-2019 - |
题
通过Rufus调度程序创建cron作业时,有什么办法吗 在cron作业的代码块内,以确定 工作本身?
我想要做的是这样的事情:
scheduler.cron '0 0 0 * * * Etc/GMT+0' do
# Nix existing jobs.
scheduler.cron_jobs.values.map { |j| if j.job_id != self.job_id then j.unschedule end }
...
end
问题是 self.job_id
.有关如何检索
当前正在触发的cron的当前job_id?
我知道有类似"triggered_threads"的东西,它返回 目前正在运行的作业。但我想要更具体的东西:该 我目前所在的代码块的job_id。
这可能吗?
解决方案
我能够通过提供调度程序来解决这个问题。使用显式标识新作业ID的可选参数进行cron方法调用:
scheduler.cron '0 0 0 * * * Etc/GMT+0', {:job_id => explicit_job_id} do
# Nix existing jobs.
scheduler.cron_jobs.values.map { |j| if j.job_id != self.job_id then j.unschedule end }
...
end
哪里 explicit_job_id
是在调度程序之前定义的一些变量。进行cron调用。
不隶属于 StackOverflow