作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我的模型中有一个 Sidekiq worker ,它看起来像这样:
class Perk < ActiveRecord::Base
include Sidekiq::Worker
include Sidekiq::Status::Worker
after_save :update_release_time
def update_release_time
if self.release_time_changed?
#if scheduled job already exists then cancel and reschedule
# Sidekiq::Status.cancel scheduled_job_id
# scheduled_job_id = NotifierWorker.perform_at(time.seconds.from_now, .....)
#elsif scheduled job doesn't exist, then schedule for the first time
# scheduled_job_id = NotifierWorker.perform_at(time.seconds.from_now, .....)
#end
end
end
end
scheduled_job_id
存在然后获取它的id?
最佳答案
API文档概述了您可以做什么,但您确实需要深入了解源代码以发现所有功能。
你可以这样做,但效率不高。这是通过 JID 查找预定作业的线性扫描。
require 'sidekiq/api'
Sidekiq::ScheduledSet.new.find_job(jid).try(:delete)
关于ruby-on-rails - rails : Cancelling a scheduled job in Sidekiq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24180899/
我是一名优秀的程序员,十分优秀!