how to delete a job in sidekiq

前端 未结 8 2022
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 20:32

I am using sidekiq in my rails app. Users of my app create reports that start a sidekiq job. However, sometimes users want to be able to cancel \"processing\" reports. Delet

8条回答
  •  再見小時候
    2020-12-07 21:14

    According to this Sidekiq documentation page to delete a job with a single id you need to iterate the queue and call .delete on it.

    queue = Sidekiq::Queue.new("mailer")
    queue.each do |job|
      job.klass # => 'MyWorker'
      job.args # => [1, 2, 3]
      job.delete if job.jid == 'abcdef1234567890'
    end
    

    There is also a plugin called sidekiq-status that provides you the ability to cancel a single job

    scheduled_job_id = MyJob.perform_in 3600
    Sidekiq::Status.cancel scheduled_job_id #=> true
    

提交回复
热议问题