I am using delayed job to perform background jobs. i am running delayed jobs with command RAILS_ENV=production bin/delayed_job -n 5 start
when i starts delayed job and checked the delayed jobs it show that jobs are running. when i checked the delayed job again after 1 hour delayed jobs status for all job was still "running". All jobs was supposed to completed in 15 minutes but even after 1 hour it is showing status as running. please help.
Below is my delayed job log file content.
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
status of jobs that are running are as below.
=> #<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">
my code to insert job in delayed job is as below.
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
I suppose you have enqueued(and start) the job in somewhere else. Thus the problem is just why the job keep running.
I think you should first make sure that processes are indeed initiated/started.
Then, the gem delayed_job_web
is a useful interface to monitor status of processes.
On the other hand, you can try setting max_run_time
to see whether delayed_job
is functioning as expected.
# config/initializers/delayed_job_config.rb
Delayed::Worker.max_run_time = 5.minutes