Delayed Job:延迟作业任务挂起

Delayed Job: Delayed job task hangs

我正在使用延迟作业来执行后台作业。我 运行 使用命令延迟作业 RAILS_ENV=production bin/delayed_job -n 5 start

当我开始延迟作业并检查延迟作业时,它显示作业是 运行。当我在 1 小时后再次检查延迟作业时,所有作业的延迟作业状态仍然是 "running"。所有作业本应在 15 分钟内完成,但即使在 1 小时后它仍显示状态 运行。请帮忙

以下是我的延迟作业日志文件内容。

I, [2015-12-22T13:10:56.463154 #15255]  INFO -- : 2015-12-22T13:10:56+0000: [Worker(delayed_job.0 host:ip-172-31-6-58 pid:15255)] Job QrCodeGenerator (id=16) RUNNING
I, [2015-12-22T13:10:56.467157 #15261]  INFO -- : 2015-12-22T13:10:56+0000: [Worker(delayed_job.1 host:ip-172-31-6-58 pid:15261)] Job QrCodeGenerator (id=17) RUNNING
I, [2015-12-22T13:10:56.544987 #15267]  INFO -- : 2015-12-22T13:10:56+0000: [Worker(delayed_job.2 host:ip-172-31-6-58 pid:15267)] Job QrCodeGenerator (id=15) RUNNING

运行 的工作状态如下。

 => #<Delayed::Backend::ActiveRecord::Job id: 15, priority: 0, attempts: 0, handler: "--- !ruby/struct:QrCodeGenerator\nclient: !ruby/obj...", last_error: nil, run_at: "2015-12-22 11:57:28", locked_at: "2015-12-22 13:10:56", failed_at: nil, locked_by: "delayed_job.2 host:ip-172-31-6-58 pid:15267", queue: nil, created_at: "2015-12-22 09:07:39", updated_at: "2015-12-22 11:57:51">
2.0.0-p598 :004 >

 => #<Delayed::Backend::ActiveRecord::Job id: 16, priority: 0, attempts: 0, handler: "--- !ruby/struct:QrCodeGenerator\nclient: !ruby/obj...", last_error: nil, run_at: "2015-12-22 09:08:06", locked_at: "2015-12-22 13:10:56", failed_at: nil, locked_by: "delayed_job.0 host:ip-172-31-6-58 pid:15255", queue: nil, created_at: "2015-12-22 09:08:06", updated_at: "2015-12-22 09:08:06">

 => #<Delayed::Backend::ActiveRecord::Job id: 17, priority: 0, attempts: 0, handler: "--- !ruby/struct:QrCodeGenerator\nclient: !ruby/obj...", last_error: nil, run_at: "2015-12-22 09:08:44", locked_at: "2015-12-22 13:10:56", failed_at: nil, locked_by: "delayed_job.1 host:ip-172-31-6-58 pid:15261", queue: nil, created_at: "2015-12-22 09:08:44", updated_at: "2015-12-22 09:08:44">

我在延迟作业中插入作业的代码如下。

QrCodeGenerator = Struct.new(:client,:request,:quantity) do
  def perform
      AuthenticationCode.save_qr_codes(client,request,quantity)
  end

  def error(job, exception)
    if request.status != "completed"
      request.update_attributes(:status => "failed")
    end
  end

  def destroy_failed_jobs?
    true
  end

  def max_attempts
    1
  end

end

我想你已经在其他地方排队(并开始)了这项工作。因此问题就是为什么工作保持 运行.

我认为你应该首先确保进程确实是 initiated/started。

那么,gem delayed_job_web一个有用的界面 来监控进程的状态。

另一方面,您可以尝试设置 max_run_time 以查看 delayed_job 是否按预期运行。

# config/initializers/delayed_job_config.rb
Delayed::Worker.max_run_time = 5.minutes