【问题标题】:How to kill sidekiq job in Rails 4 with ActiveJob如何使用 ActiveJob 在 Rails 4 中杀死 sidekiq 作业
【发布时间】:2016-03-25 09:59:19
【问题描述】:

假设我们有测试工作:

class TestJob < ActiveJob::Base
  queue_as :default

  def perform(video)
    video.process
  end
end

之后我们运行bundle exec sidekiq start

并在 Rails 控制台的新终端窗口中运行

Video.first.pending!; TestJob.perform_later(Video.first)

Job 正在运行,ffmpeg 在后台,一切正常,但根据official sidekiq wiki docs 我试试:

require 'sidekiq/api'
Sidekiq::Queue.new
=> #<Sidekiq::Queue:0x00000006406978 @name="default", @rname="queue:default">

Sidekiq::Queue.new.each {|job| puts job}
=> nil
Sidekiq::Queue.new.size
=> 0
ss = Sidekiq::ScheduledSet.new
=> #<Sidekiq::ScheduledSet:0x000000064a4330 @_size=0, @name="schedule">
ss.size
=> 0

为什么没有工作?作业运行成功(我也在 sidekiq 启动的第一个窗口中看到它,但我无法在 rails 控制台中看到并删除它)

如果有帮助,我正在使用 Ubuntu 14

此致,鲁斯兰。

统一更新: 看起来 ps = Sidekiq::ProcessSet.new; ps.each(&amp;:quiet!) 作品 ,但它不会阻止我的 ffmpeg 在内部处理这部分代码:

cmd = "ffmpeg -i #{input_file.shellescape} #{options} -threads 0 -y #{self.path + outfile}"
pid = spawn(cmd, :out => output_file, :err => output_file)
Process.wait(pid)

如何阻止它?

【问题讨论】:

  • 不,作业正在 100% 运行

标签: ruby-on-rails ruby ruby-on-rails-4 sidekiq rails-activejob


【解决方案1】:

我使用 sidekiq Web UI 和各种队列来完成我的工作。如果我意识到特定的工作失败了,我可以清除同一类后续工作的队列。

【讨论】:

    【解决方案2】:

    如果作业正在处理,则不再排队。

    【讨论】:

    • 欧,@Mike Perkham,非常感谢,但是如何找到加工工作?
    • Sidekiq 没有提供任何停止作业的方法,因为它不能安全地完成。你必须在你的工作中实现一些东西,定期检查它是否应该停止。
    猜你喜欢
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 2019-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 2017-02-19
    • 2016-12-27
    相关资源
    最近更新 更多