我正在使用延迟工作来执行后台工作。我正在使用命令RAILS_ENV=production bin/delayed_job -n 5 start
当我开始延迟工作并检查延迟的工作时,它表明工作正在运行。当我在1小时后再次检查延迟的工作时,所有工作的延迟工作状态仍在“运行”。所有工作都应在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
答案 0 :(得分:2)
我想你已经在其他地方入队(并开始)这份工作。因此问题就在于工作继续运行的原因。
我认为您应首先确保流程确实已启动/启动。
然后,gem delayed_job_web
一个有用的界面 来监控进程的状态。
另一方面,您可以尝试设置max_run_time
以查看delayed_job
是否按预期运行。
# config/initializers/delayed_job_config.rb
Delayed::Worker.max_run_time = 5.minutes