【问题标题】:Determine job_id from within the code-block for a cron job in Rufus Scheduler (rails 3.2)在 Rufus Scheduler (rails 3.2) 中为 cron 作业的代码块确定 job_id
【发布时间】:2012-07-29 14:43:17
【问题描述】:

通过 Rufus 调度器创建 cron 作业时,有什么方法吗 在 cron 作业的代码块中确定作业的 job_id 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。

这可能吗?

【问题讨论】:

    标签: ruby-on-rails-3 rufus-scheduler


    【解决方案1】:

    我能够通过为 scheduler.cron 方法调用提供一个明确标识新作业 ID 的可选参数来解决此问题:

    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 是在调用 scheduler.cron 之前定义的某个变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 2014-03-18
      • 1970-01-01
      • 2016-06-14
      • 1970-01-01
      相关资源
      最近更新 更多