简体   繁体   English

如何使用ActiveJob杀死Rails 4中的sidekiq作业

[英]How to kill sidekiq job in Rails 4 with ActiveJob

Let's say we have test job: 假设我们有测试工作:

class TestJob < ActiveJob::Base
  queue_as :default

  def perform(video)
    video.process
  end
end

After it we run bundle exec sidekiq start 之后,我们运行bundle exec sidekiq start

And run in new terminal window in rails console 并在Rails控制台的新终端窗口中运行

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

Job is running, ffmpeg is on background, everything is fine, but according to official sidekiq wiki docs I try: 作业正在运行,ffmpeg在后台运行,一切都很好,但是根据官方的sidekiq Wiki文档,我尝试:

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

Why there is no jobs? 为什么没有工作? The job is running successfully ( I see it also in first window where sidekiq starts, but I can't see and delete it in rails console ) 作业运行成功(我在sidekiq启动的第一个窗口中也看到了它,但是在rails控制台中看不到并删除了它)

I am using Ubuntu 14 if it helps 我正在使用Ubuntu 14,如果有帮助

With best regards, Ruslan. 最好的问候,罗斯兰。

UPD: It looks that ps = Sidekiq::ProcessSet.new; ps.each(&:quiet!) UPD:看来ps = Sidekiq::ProcessSet.new; ps.each(&:quiet!) ps = Sidekiq::ProcessSet.new; ps.each(&:quiet!) works , but it doesn't stop my ffmpeg process this part of code internally in process: ps = Sidekiq::ProcessSet.new; ps.each(&: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)

How to stop it? 如何停止呢?

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

I use sidekiq web UI and various queues for my jobs. 我为我的工作使用sidekiq Web UI和各种队列。 If I realize that particular job is failing I can clear out the queue of subsequent jobs of the same class. 如果我发现某项特定的作业失败,则可以清除相同类别的后续作业的队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM