Rails 5 delayed job, how to check the job status - ruby-on-rails

I am using a delayed job on a Rails 5 project with the 'delayed_job_active_record' gem.
I can't figure out how to check on the status of the job.
I managed to get delayed job to run. The jobs are failing due to an issue with processing uploaded files (that's another issue).
In my controller:
def create
#upload = Upload.create(status: "in progress")
#upload.delay.create_ln(lecture_note_params, current_user, #upload.id)
render json: {"status": #upload.status, "id": #upload.id}, status: 200
end
Here's my model code for the upload model:
class Upload < ApplicationRecord
def create_ln(lecture_note_params, current_user, upload_id)
#lecture_note = LectureNote.new(lecture_note_params.merge(user: current_user))
#lecture_note.upload_id = upload_id
if #lecture_note.save
#nothing
else
logger.info #lecture_note.errors.full_messages.to_sentence
#upload.update(error: #lecture_note.errors.full_messages.to_sentence, status: "error")
end
end
end
The lecture notes don't save. They fail for the reason mentioned above. I need the upload model to update with the error status. How can I do that?
I can see the delayed job in the console :
irb(main):002:0> ap Delayed::Job.last
D, [2019-12-12T06:12:08.014249 #4] DEBUG -- : Delayed::Backend::ActiveRecord::Job Load (6.3ms) SELECT `delayed_jobs`.* FROM `delayed_jobs` ORDER BY `delayed_jobs`.`id` DESC LIMIT 1
#<Delayed::Backend::ActiveRecord::Job:0x0000561edb710f70> {
:id => 16,
:priority => 0,
:attempts => 1,
:handler => "### ALL KINDS OF STUFF - REDACTED ###",
:run_at => Thu, 12 Dec 2019 06:10:32 UTC +00:00,
:locked_at => nil,
:failed_at => Thu, 12 Dec 2019 06:11:17 UTC +00:00,
:locked_by => nil,
:queue => nil,
:created_at => Thu, 12 Dec 2019 06:10:32 UTC +00:00,
:updated_at => Thu, 12 Dec 2019 06:11:17 UTC +00:00
}
After the job fails, the "failed_at" field is updated. How can I access that and update my upload model?
Here is the log file while a file is uploading:
D, [2019-12-12T06:11:17.846638 #4] DEBUG -- : Upload Load (1.1ms) SELECT `uploads`.* FROM `uploads` WHERE `uploads`.`id` = 31 LIMIT 1
D, [2019-12-12T06:11:17.852741 #4] DEBUG -- : User Load (1.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
[Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] Job Upload#create_ln (id=16) RUNNING
I, [2019-12-12T06:11:17.853180 #4] INFO -- : 2019-12-12T06:11:17+0000: [Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] Job Upload#create_ln (id=16) RUNNING
D, [2019-12-12T06:11:17.855002 #4] DEBUG -- : (1.2ms) BEGIN
I, [2019-12-12T06:11:17.855200 #4] INFO -- : pdf to html running..............
I, [2019-12-12T06:11:17.855268 #4] INFO -- : step 0 ..............
I, [2019-12-12T06:11:17.855326 #4] INFO -- : step 1 ..............
I, [2019-12-12T06:11:17.855388 #4] INFO -- : step 2 ..............
D, [2019-12-12T06:11:17.856673 #4] DEBUG -- : (1.1ms) ROLLBACK
[Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] Job Upload#create_ln (id=16) FAILED (0 prior attempts) with IOError: uninitialized stream
E, [2019-12-12T06:11:17.857261 #4] ERROR -- : 2019-12-12T06:11:17+0000: [Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] Job Upload#create_ln (id=16) FAILED (0 prior attempts) with IOError: uninitialized stream
[Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] Job Upload#create_ln (id=16) FAILED permanently because of 1 consecutive failures
E, [2019-12-12T06:11:17.857416 #4] ERROR -- : 2019-12-12T06:11:17+0000: [Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] Job Upload#create_ln (id=16) FAILED permanently because of 1 consecutive failures
D, [2019-12-12T06:11:17.858576 #4] DEBUG -- : (0.9ms) BEGIN
D, [2019-12-12T06:11:17.861961 #4] DEBUG -- : SQL (1.6ms) UPDATE `delayed_jobs` SET `last_error` = 'uninitialized stream\n/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tempfile.rb:221:in `path\'\n/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tempfile.rb:221:in `path\'\n/app/app/models/lecture_note.rb:60:in `pdf_to_html\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:382:in `block in make_lambda\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:150:in `block (2 levels) in halting_and_conditional\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:770:in `block (2 levels) in deprecated_false_terminator\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:769:in `catch\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:769:in `block in deprecated_false_terminator\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:454:in `block in call\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:454:in `each\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:454:in `call\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__\'\n/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.1/lib/active_support/callbacks.rb:750:in `_run_validation_callbacks\'\n/app/vendor/bundle/ruby/2.6.0/gems/activemodel-5.0.7.1/lib/active_model/validations/callbacks.rb:113:in `run_validations!\'\n/app/vendor/bundle/ruby/2.6.0/gems/activemodel-5.0.7.1/lib/active_model/validations.rb:338:in `valid?\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/validations.rb:65:in `valid?\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/validations.rb:82:in `perform_validations\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/validations.rb:44:in `save\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/attribute_methods/dirty.rb:22:in `save\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/transactions.rb:319:in `block (2 levels) in save\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/transactions.rb:211:in `transaction\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/transactions.rb:392:in `with_transaction_returning_status\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/transactions.rb:319:in `block in save\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/transactions.rb:334:in `rollback_active_record_state!\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/transactions.rb:318:in `save\'\n/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.0.7.1/lib/active_record/suppressor.rb:41:in `save\'\n/app/app/models/upload.rb:7:in `create_ln\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/performable_method.rb:26:in `perform\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/backend/base.rb:81:in `block in invoke_job\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:61:in `block in initialize\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:66:in `execute\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:40:in `run_callbacks\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/backend/base.rb:78:in `invoke_job\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:230:in `block (2 levels) in run\'\n/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/timeout.rb:93:in `block in timeout\'\n/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/timeout.rb:103:in `timeout\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:230:in `block in run\'\n/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/benchmark.rb:308:in `realtime\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:229:in `run\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:312:in `block in reserve_and_run_one_job\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:61:in `block in initialize\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:66:in `execute\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:40:in `run_callbacks\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:312:in `reserve_and_run_one_job\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:213:in `block in work_off\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:212:in `times\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:212:in `work_off\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:175:in `block (4 levels) in start\'\n/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/benchmark.rb:308:in `realtime\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:174:in `block (3 levels) in start\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:61:in `block in initialize\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:66:in `execute\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:40:in `run_callbacks\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:173:in `block (2 levels) in start\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:172:in `loop\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:172:in `block in start\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:61:in `block in initialize\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:79:in `block in add\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:66:in `execute\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/lifecycle.rb:40:in `run_callbacks\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/worker.rb:171:in `start\'\n/app/vendor/bundle/ruby/2.6.0/gems/delayed_job-4.1.8/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `block in execute\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `each\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `execute\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:214:in `block in invoke_with_call_chain\'\n/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:194:in `invoke_with_call_chain\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:183:in `invoke\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:160:in `invoke_task\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `block (2 levels) in top_level\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `each\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `block in top_level\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:125:in `run_with_threads\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:110:in `top_level\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:83:in `block in run\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:80:in `run\'\n/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>\'\n/app/vendor/bundle/ruby/2.6.0/bin/rake:23:in `load\'\n/app/vendor/bundle/ruby/2.6.0/bin/rake:23:in `<top (required)>\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `load\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `kernel_load\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:28:in `run\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:463:in `exec\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:27:in `dispatch\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:18:in `start\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors\'\n/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>\'\n/app/bin/bundle:3:in `load\'\n/app/bin/bundle:3:in `<main>\'', `attempts` = 1, `failed_at` = '2019-12-12 06:11:17', `updated_at` = '2019-12-12 06:11:17' WHERE `delayed_jobs`.`id` = 16
D, [2019-12-12T06:11:17.867680 #4] DEBUG -- : (5.1ms) COMMIT
D, [2019-12-12T06:11:17.870699 #4] DEBUG -- : SQL (1.8ms) UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_at` = '2019-12-12 06:11:17', `delayed_jobs`.`locked_by` = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4' WHERE ((run_at <= '2019-12-12 06:11:17.867786' AND (locked_at IS NULL OR locked_at < '2019-12-12 02:11:17.867819') OR locked_by = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
[Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] 8 jobs processed at 13.8130 j/s, 8 failed
I, [2019-12-12T06:11:17.870885 #4] INFO -- : 2019-12-12T06:11:17+0000: [Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] 8 jobs processed at 13.8130 j/s, 8 failed
D, [2019-12-12T06:11:17.873258 #4] DEBUG -- : SQL (1.2ms) UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_at` = '2019-12-12 06:11:17', `delayed_jobs`.`locked_by` = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4' WHERE ((run_at <= '2019-12-12 06:11:17.870973' AND (locked_at IS NULL OR locked_at < '2019-12-12 02:11:17.871010') OR locked_by = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
D, [2019-12-12T06:11:22.878755 #4] DEBUG -- : SQL (1.5ms) UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_at` = '2019-12-12 06:11:22', `delayed_jobs`.`locked_by` = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4' WHERE ((run_at <= '2019-12-12 06:11:22.876103' AND (locked_at IS NULL OR locked_at < '2019-12-12 02:11:22.876164') OR locked_by = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
D, [2019-12-12T06:11:27.882776 #4] DEBUG -- : SQL (1.6ms) UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_at` = '2019-12-12 06:11:27', `delayed_jobs`.`locked_by` = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4' WHERE ((run_at <= '2019-12-12 06:11:27.880101' AND (locked_at IS NULL OR locked_at < '2019-12-12 02:11:27.880160') OR locked_by = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
D, [2019-12-12T06:11:32.890712 #4] DEBUG -- : SQL (1.6ms) UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_at` = '2019-12-12 06:11:32', `delayed_jobs`.`locked_by` = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4' WHERE ((run_at <= '2019-12-12 06:11:32.887163' AND (locked_at IS NULL OR locked_at < '2019-12-12 02:11:32.887243') OR locked_by = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
D, [2019-12-12T06:11:37.894751 #4] DEBUG -- : SQL (1.5ms) UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_at` = '2019-12-12 06:11:37', `delayed_jobs`.`locked_by` = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4' WHERE ((run_at <= '2019-12-12 06:11:37.892094' AND (locked_at IS NULL OR locked_at < '2019-12-12 02:11:37.892153') OR locked_by = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
^C[Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] Exiting...
I, [2019-12-12T06:11:39.976787 #4] INFO -- : 2019-12-12T06:11:39+0000: [Worker(host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4)] Exiting...
D, [2019-12-12T06:11:42.902214 #4] DEBUG -- : SQL (5.4ms) UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_by` = NULL, `delayed_jobs`.`locked_at` = NULL WHERE `delayed_jobs`.`locked_by` = 'host:575e618d-28f3-49a1-8545-88afa11b60d1 pid:4'

OK I found the solution. Tun's answer pointed me in the general direction (very general direction) but led me to it.
delayed_job has callbacks but I didn't know where to put them, or how to use them. They simply go in the model where the job method takes place. That wasn't obvious in the available documentation (to me anyway).
I was looking at this the wrong way. I already have the upload class to manage the creation of the lecture notes. So using the callbacks I can have the job update the class with the status. That's what we needed in the end.
The def failure(job) method did the trick!
I don't 100% understand how these callbacks actually work behind the scenes but they do work.
class Upload < ApplicationRecord
def create_ln(lecture_note_params, current_user, upload_id)
#lecture_note = LectureNote.new(lecture_note_params.merge(user: current_user))
#lecture_note.upload_id = upload_id
# if #lecture_note.save
# #nothing
# else
# logger.info #lecture_note.errors.full_messages.to_sentence
# #upload.update(error: #lecture_note.errors.full_messages.to_sentence, status: "error")
# end
begin
#lecture_note.save
rescue Exception => e
puts #lecture_note.errors.full_messages.to_sentence
self.update(error: #lecture_note.errors.full_messages.to_sentence, status: "error")
end
end
def success(job)
puts "Job complete ------->"
end
def error(job, exception)
puts "Job failed ERROR ------->"
puts #lecture_note.errors.full_messages.to_sentence
self.update(error: #lecture_note.errors.full_messages.to_sentence, status: "error")
end
# def after(job)
# # Do something useful here
# end
def failure(job)
puts "Job failed FAILURE ------->"
puts #lecture_note.errors.full_messages.to_sentence
self.update(error: #lecture_note.errors.full_messages.to_sentence, status: "error")
end
end

Generally, we should not check the job. The job should report back. (Observer pattern - I think)
I usually do one or combination of the followings
ActionCable to inform progress of the job (exception in your case)
Catch Exception in the job and update Upload with status
Use third party gem (such as activity_notification for notification.
DelayedJob proposed Global Hooks but I think it is not implemented yet.

Related

Heroku scheduler calls job but it doesn't get executed

I am hosting my app with Heroku, and have a task in the scheduler.rake file (to be called by Heroku Scheduler):
task :send_recipe_summary => :environment do
puts "Calling send recipe summary slack message job..."
SendRecipeSummarySlackMessageJob.perform_later
puts "Done!"
end
When this task gets called (by the scheduler or in the console) it says that the task gets enqueued:
➜ Plant-as-Usual-2 git:(master) heroku run bundle exec rake send_recipe_summary
Running bundle exec rake send_recipe_summary on ⬢ plant-as-usual-2... up, run.5548 (Hobby)
Calling send recipe summary slack message job...
I, [2020-09-24T16:25:50.193685 #4] INFO -- : [ActiveJob] Enqueued SendRecipeSummarySlackMessageJob (Job ID: a4110651-a9fa-4030-96ef-db4caf64c7e5) to Async(default)
Done!
However, in the logs, the job does not get enqueued, and the Slack message never gets sent:
2020-09-24T16:25:35.913315+00:00 app[api]: Starting process with command `bundle exec rake send_recipe_summary` by user jonappleseed#email.com
2020-09-24T16:25:44.008993+00:00 heroku[run.5548]: Awaiting client
2020-09-24T16:25:44.039520+00:00 heroku[run.5548]: State changed from starting to up
2020-09-24T16:25:44.291580+00:00 heroku[run.5548]: Starting process with command `bundle exec rake send_recipe_summary`
2020-09-24T16:25:49.334067+00:00 app[worker.1]: D, [2020-09-24T16:25:49.333949 #4] DEBUG -- : [1m[36mDelayed::Backend::ActiveRecord::Job Load (1.5ms)[0m [1m[37mUPDATE "delayed_jobs" SET locked_at = '2020-09-24 16:25:49.331558', locked_by = 'host:9b1fc7b1-4107-427f-8f49-f058b41b7906 pid:4' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2020-09-24 16:25:49.330595' AND (locked_at IS NULL OR locked_at < '2020-09-24 12:25:49.330627') OR locked_by = 'host:9b1fc7b1-4107-427f-8f49-f058b41b7906 pid:4') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *[0m
2020-09-24T16:25:53.372387+00:00 heroku[run.5548]: Process exited with status 0
2020-09-24T16:25:53.407641+00:00 heroku[run.5548]: State changed from up to complete
2020-09-24T16:26:49.394474+00:00 app[worker.1]: D, [2020-09-24T16:26:49.394376 #4] DEBUG -- : [1m[36mDelayed::Backend::ActiveRecord::Job Load (1.5ms)[0m [1m[37mUPDATE "delayed_jobs" SET locked_at = '2020-09-24 16:26:49.392377', locked_by = 'host:9b1fc7b1-4107-427f-8f49-f058b41b7906 pid:4' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2020-09-24 16:26:49.391803' AND (locked_at IS NULL OR locked_at < '2020-09-24 12:26:49.391827') OR locked_by = 'host:9b1fc7b1-4107-427f-8f49-f058b41b7906 pid:4') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *[0m
However, if I run the job itself (rather than the task), everything works as expected, and the message does get sent:
irb(main):002:0> SendRecipeSummarySlackMessageJob.perform_later
I, [2020-09-24T16:22:45.268729 #4] INFO -- : [ActiveJob] Enqueued SendRecipeSummarySlackMessageJob (Job ID: 8285bb7f-9646-42bb-9901-8d219ca1175c) to Async(default)
=> #<SendRecipeSummarySlackMessageJob:0x000055b1a768dfb8 #arguments=[], #job_id="8285bb7f-9646-42bb-9901-8d219ca1175c", #queue_name="default", #priority=nil, #executions=0, #exception_executions={}, #provider_job_id="c41cedd7-e5a5-4a7d-9e64-280d2ec81e1e">
irb(main):003:0> I, [2020-09-24T16:22:45.269348 #4] INFO -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] Performing SendRecipeSummarySlackMessageJob (Job ID: 8285bb7f-9646-42bb-9901-8d219ca1175c) from Async(default) enqueued at 2020-09-24T16:22:45Z
D, [2020-09-24T16:22:46.412105 #4] DEBUG -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] (1.5ms) SELECT COUNT(*) FROM "recipes" WHERE "recipes"."state" = $1 [["state", "awaiting_approval"]]
D, [2020-09-24T16:22:46.413683 #4] DEBUG -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] (1.0ms) SELECT COUNT(*) FROM "recipes" WHERE "recipes"."state" = $1 [["state", "incomplete"]]
I, [2020-09-24T16:22:46.415123 #4] INFO -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] Enqueued SendSlackMessageJob (Job ID: c640b706-9920-4639-a1a0-4c7dbec15c39) to Async(default) with arguments: "There are no recipes awaiting approval, and 1 incomplete recipe https://www.plantasusual.com/admin", {:nature=>"inform"}
I, [2020-09-24T16:22:46.415260 #4] INFO -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] Performed SendRecipeSummarySlackMessageJob (Job ID: 8285bb7f-9646-42bb-9901-8d219ca1175c) from Async(default) in 1145.43ms
I, [2020-09-24T16:22:46.415882 #4] INFO -- : [ActiveJob] [SendSlackMessageJob] [c640b706-9920-4639-a1a0-4c7dbec15c39] Performing SendSlackMessageJob (Job ID: c640b706-9920-4639-a1a0-4c7dbec15c39) from Async(default) enqueued at 2020-09-24T16:22:46Z with arguments: "There are no recipes awaiting approval, and 1 incomplete recipe https://www.plantasusual.com/admin", {:nature=>"inform"}
I, [2020-09-24T16:22:46.591446 #4] INFO -- : [ActiveJob] [SendSlackMessageJob] [c640b706-9920-4639-a1a0-4c7dbec15c39] Performed SendSlackMessageJob (Job ID: c640b706-9920-4639-a1a0-4c7dbec15c39) from Async(default) in 175.12ms
Can anyone help me understand why the job runs as expected when run from the console, but it doesn't work when run from the scheduler?
Thank you to anyone who can help!
It seems you have not enabled worker on heroku bundle exec rake jobs:work.
It is a paid service. goto: your_app > resource tab and enable it from there. this link could be helpful

When i deploy project on heroku db doesnt work normal

So i have this code in my mode
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string
# surname :string
# user_id :integer
# count :integer default(0)
# was :boolean default(FALSE)
# qrcode :string
# created_at :datetime not null
# updated_at :datetime not null
#
class User < ApplicationRecord
validates :name, presence: true
validates :surname, presence: true
validates :user_id, presence: true
after_create :generate_qr
private
def generate_qr
ian = User.find(id)
ian.update_attribute(:qrcode, "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + user_id.to_s)
# update_attribute(:qrcode, "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + user_id.to_s)
end
end
Its work fine and generate qr code on my local host. But when i deploy on heroku i have this errors in heroku logs.
2018-06-30T14:23:37.200657+00:00 app[web.1]: I, [2018-06-30T14:23:37.200507 #4] INFO -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] Parameters: {"utf8"=>"✓", "authenticity_token"=>"mBkhE7alyyKGtS4v+tnW2Vpg6c1z0kwQfbnftqTWdSukTpre29vkqVmeuVoGR7NJzs0EoxiQv0rS+WzJ4hUSOw==", "user"=>{"name"=>"fdsfds", "surname"=>"fdsfdsfds", "user_id"=>"53454"}, "commit"=>"Create User"}
2018-06-30T14:23:37.204598+00:00 app[web.1]: D, [2018-06-30T14:23:37.204527 #4] DEBUG -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] (1.1ms) BEGIN
2018-06-30T14:23:37.207575+00:00 app[web.1]: D, [2018-06-30T14:23:37.207496 #4] DEBUG -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] User Create (1.5ms) INSERT INTO "users" ("name", "surname", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "fdsfds"], ["surname", "fdsfdsfds"], ["user_id", 53454], ["created_at", "2018-06-30 14:23:37.204956"], ["updated_at", "2018-06-30 14:23:37.204956"]]
2018-06-30T14:23:37.214137+00:00 app[web.1]: D, [2018-06-30T14:23:37.214060 #4] DEBUG -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] User Load (1.3ms)
SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 7], ["LIMIT", 1]]
2018-06-30T14:23:37.215729+00:00 app[web.1]: D, [2018-06-30T14:23:37.215664 #4] DEBUG -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] (1.1ms) ROLLBACK
2018-06-30T14:23:37.224955+00:00 app[web.1]: I, [2018-06-30T14:23:37.224881 #4] INFO -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] Completed 500 Internal Server Error in 24ms (ActiveRecord: 6.1ms)
2018-06-30T14:23:37.225904+00:00 app[web.1]: F, [2018-06-30T14:23:37.225838 #4] FATAL -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a]
2018-06-30T14:23:37.226043+00:00 app[web.1]: F, [2018-06-30T14:23:37.225990 #4] FATAL -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] NoMethodError (undefined method `qrcode=' for #<User:0x00000004fd1d68>):
2018-06-30T14:23:37.226091+00:00 app[web.1]: F, [2018-06-30T14:23:37.226046 #4] FATAL -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a]
2018-06-30T14:23:37.226146+00:00 app[web.1]: F, [2018-06-30T14:23:37.226103 #4] FATAL -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] app/models/user.rb:25:in `generate_qr'
Someone please help. I dont know where is error. Its work fine on my localhost.

Error while reserving job: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly

Delayed jobs service is stopping after less than 1 hour of its starting time with the following log:
I, [2018-02-26T06:00:26.580458 #11439] INFO -- : 2018-02-26T06:00:26+0400: [Worker(delayed_job host:myhost pid:11439)] Starting job worker
I, [2018-02-26T06:00:26.664929 #11439] INFO -- : 2018-02-26T06:00:26+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41019) RUNNING
I, [2018-02-26T06:00:27.342994 #11439] INFO -- : 2018-02-26T06:00:27+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41019) COMPLETED after 0.6779
I, [2018-02-26T06:00:27.346526 #11439] INFO -- : 2018-02-26T06:00:27+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41020) RUNNING
I, [2018-02-26T06:00:27.470858 #11439] INFO -- : 2018-02-26T06:00:27+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41020) COMPLETED after 0.1242
I, [2018-02-26T06:00:27.474937 #11439] INFO -- : 2018-02-26T06:00:27+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41024) RUNNING
I, [2018-02-26T06:00:27.603043 #11439] INFO -- : 2018-02-26T06:00:27+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41024) COMPLETED after 0.1280
I, [2018-02-26T06:00:27.606702 #11439] INFO -- : 2018-02-26T06:00:27+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41025) RUNNING
I, [2018-02-26T06:00:27.725715 #11439] INFO -- : 2018-02-26T06:00:27+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41025) COMPLETED after 0.1189
I, [2018-02-26T06:00:27.728021 #11439] INFO -- : 2018-02-26T06:00:27+0400: [Worker(delayed_job host:myhost pid:11439)] 4 jobs processed at 3.4871 j/s, 0 failed
I, [2018-02-26T06:14:48.287220 #11439] INFO -- : 2018-02-26T06:14:48+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41027) RUNNING
I, [2018-02-26T06:14:48.414079 #11439] INFO -- : 2018-02-26T06:14:48+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41027) COMPLETED after 0.1267
I, [2018-02-26T06:14:48.416335 #11439] INFO -- : 2018-02-26T06:14:48+0400: [Worker(delayed_job host:myhost pid:11439)] 1 jobs processed at 7.3771 j/s, 0 failed
I, [2018-02-26T06:16:33.492435 #11439] INFO -- : 2018-02-26T06:16:33+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41028) RUNNING
I, [2018-02-26T06:16:33.613684 #11439] INFO -- : 2018-02-26T06:16:33+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41028) COMPLETED after 0.1211
I, [2018-02-26T06:16:33.615953 #11439] INFO -- : 2018-02-26T06:16:33+0400: [Worker(delayed_job host:myhost pid:11439)] 1 jobs processed at 7.8121 j/s, 0 failed
I, [2018-02-26T06:22:33.853678 #11439] INFO -- : 2018-02-26T06:22:33+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41030) RUNNING
I, [2018-02-26T06:22:33.967338 #11439] INFO -- : 2018-02-26T06:22:33+0400: [Worker(delayed_job host:myhost pid:11439)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=41030) COMPLETED after 0.1136
I, [2018-02-26T06:22:33.970307 #11439] INFO -- : 2018-02-26T06:22:33+0400: [Worker(delayed_job host:myhost pid:11439)] 1 jobs processed at 8.2735 j/s, 0 failed
I, [2018-02-26T06:38:24.595215 #11439] INFO -- : 2018-02-26T06:38:24+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:38:24.593926', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:38:24.593351' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:38:24.593398') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:38:29.597026 #11439] INFO -- : 2018-02-26T06:38:29+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:38:29.596061', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:38:29.595477' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:38:29.595524') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:38:34.598775 #11439] INFO -- : 2018-02-26T06:38:34+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:38:34.597856', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:38:34.597278' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:38:34.597325') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:38:39.600772 #11439] INFO -- : 2018-02-26T06:38:39+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:38:39.599713', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:38:39.599063' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:38:39.599110') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:38:44.602546 #11439] INFO -- : 2018-02-26T06:38:44+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:38:44.601568', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:38:44.601024' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:38:44.601072') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:38:49.604286 #11439] INFO -- : 2018-02-26T06:38:49+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:38:49.603369', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:38:49.602808' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:38:49.602863') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:38:54.606189 #11439] INFO -- : 2018-02-26T06:38:54+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:38:54.605111', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:38:54.604563' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:38:54.604613') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:38:59.608610 #11439] INFO -- : 2018-02-26T06:38:59+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:38:59.607243', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:38:59.606483' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:38:59.606539') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:39:04.610465 #11439] INFO -- : 2018-02-26T06:39:04+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:39:04.609457', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:39:04.608876' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:39:04.608926') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
I, [2018-02-26T06:39:09.612201 #11439] INFO -- : 2018-02-26T06:39:09+0400: [Worker(delayed_job host:myhost pid:11439)] Error while reserving job: PG::ConnectionBad: PQsocket() can't get socket descriptor: UPDATE "delayed_jobs" SET locked_at = '2018-02-26 02:39:09.611263', locked_by = 'delayed_job host:myhost pid:11439' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2018-02-26 02:39:09.610721' AND (locked_at IS NULL OR locked_at < '2018-02-25 22:39:09.610770') OR locked_by = 'delayed_job host:myhost pid:11439') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
database.yml
production:
adapter: postgresql
encoding: unicode
database: myapp
port: 5432
pool: 5
username: username
password: password
reconnect: true
Please can anyone just explain the reason of this error and how to avoid it:
Error while reserving job: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly
Update:
I believe this issue is not related to delayed jobs, since I'm getting same error while I'm doing some normal DB queries. So DB is restarting for some reason and this why delayed job service is stopping.
As per commented by #LaurenzAlbe , below are some issues found in /var/log/postgresql/postgresql-9.3-main.log:
LOG: connection received: host=10.10.10.15 port=57322
LOG: replication connection authorized: user=MyDBUser
FATAL: must be superuser or replication role to start walsender
LOG: could not receive data from client: Connection reset by peer
LOG: disconnection: session time: 0:06:18.911 user=MyDBUser database=MyDB host=127.0.0.1 port=34040
./systemd: 36: kill: Operation not permitted
WARNING: skipping "delayed_jobs" --- only table or database owner can analyze it
After some research, I believe delayed jobs have a memory leak issue, which is solved by using config.cache_classes = true because delayed jobs keeps reloading classes every now and then.
I had the same issue where delayed job process used more than 90%+ of memory and it crashed with the same error, even though I had cached classes, but I was running delayed jobs without RAILS_ENV, which caused them to load in development and ignore the other environment settings.
This problem can also be caused by:
Rails's database idle_timeout setting, which is 300 seconds by default. This means that if a connection is idle for more than 300 seconds, the server will close it.
PgBouncer client_idle_timeout setting. This setting controls how long a connection can be idle before PgBouncer closes it. If this setting is set too low, it can cause the same errors as Rails's idle_timeout.
PostgreSQL idle_session_timeout settings (from PostgreSQL 14) and idle_in_transaction_session_timeout(for sessions that were idle in transaction).
TCP or other network or firewall timeouts(e.g. there is a case of the timeout in Azure Cloud)
And to solve this problem, there are a few possible solutions:
Speed up slow processing
Increase the idle_timeout(or another guilty timeout) setting to a higher value to prevent a server from closing idle connections too soon.
Add a database setting called reaping_frequency: 10, which will clear and restore connections more frequently to prevent them from becoming idle.
Add manual reconnection, like the code snippet below, which releases the connection and re-establishes it before saving a record to the database.
ActiveRecord::Base.connection_pool.release_connection
ActiveRecord::Base.connection_pool.with_connection do
# save record in database
end
Links:
(1)(2)(3)(4) Info about reaping_frequency
(5)(6) Info about Rails's idle_timeout
(7)(8)(9) Solutions with manual reconnection

Rails delayed_job stuck on runnin

I am trying to use a very basic delayed job on rails:
class ImportJob < Struct.new(:job_params)
def perform
#blank perform
end
end
And When I queue that job all I see in rake:jobs is that the job is RUNNING, but it never finishes:
Delayed::Job.enqueue ImportJob.new(job_params)
Furthermore if I run the job worker from the rails console I see the job get 'locked' and then immediately deleted:
2.1.2 :001 > work = Delayed::Worker.new
=> #<Delayed::Worker:0x007f8a8c4d2ee8 #quiet=true, #failed_reserve_count=0>
2.1.2 :002 > work.start
Delayed::Backend::ActiveRecord::Job Load (1.8ms) SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE ((run_at <= '2014-07-16 19:10:54.367527' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:54.367862') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 5
Delayed::Backend::ActiveRecord::Job Load (3.5ms) SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE ((run_at <= '2014-07-16 19:10:59.386290' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:59.386563') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 5
SQL (5.9ms) UPDATE "delayed_jobs" SET "locked_at" = '2014-07-16 19:10:59.387743', "locked_by" = 'host:jerrods-mbp.raleigh.ibm.com pid:36564' WHERE "delayed_jobs"."id" IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE "delayed_jobs"."id" = 6 AND ((run_at <= '2014-07-16 19:10:59.386290' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:59.386563') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC)
Delayed::Backend::ActiveRecord::Job Load (0.7ms) SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE "delayed_jobs"."id" = ? LIMIT 1 [["id", 6]]
(0.1ms) begin transaction
SQL (0.5ms) DELETE FROM "delayed_jobs" WHERE "delayed_jobs"."id" = ? [["id", 6]]
(2.6ms) commit transaction
Has anyone ever seen this behavior before?
Alright so after reading various other threads on here and other places I came by the following solution:
I realized it was failing silently for whatever reason so I added Delayed::Worker.destroy_failed_jobs = false config/application.rb
With that line added I was able to go in the console and get Delayed::Job.last.last_error and it told me that my job file wasn't being loaded in rake for whatever reason
To solve this I created a custom.rb in initlializers and added the following line:
require 'my_class'
Hopefully this will help someone else
I don't see anything out of the ordinary here. When a job completes successfully it is deleted from the delayed_jobs queue / database table. You could have your job raise an error and see what happens when one doesn't complete successfully:
def perform
raise "BOOM, goes the dynamite!"
end
It should be outputting a count of jobs completed successfully in any given "run period", however. See the source here for that.

SQLite3::SQLException: cannot commit - no transaction is active

I am trying to test the sending on an email by DelayedJob using cucumber. The feature actually works in the browser (in both development and production environments) but I'm running into a weird SQlite3 exception when I try to test it.
The test log is at the bottom. As you can see, it fails with an SQLite3::SQLException just after inserting the email sending job into the queue.
According to Delayed::Job the reason for the failure is:
Delayed::DeserializationError
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/psych_ext.rb:108:in `rescue in visit_Psych_Nodes_Mapping_with_class'
Anyone got any idea what is happening here?
I found a related question but the problem there doesn't appear to be constrained to the test environment. Thus I don't think the solution will be the same.
SQLite3 Error - cannot rollback - no transaction is active
Here's the full test trace:
SQL (82.7ms) INSERT INTO "delayed_jobs" ("attempts", "created_at", "failed_at", "handler", "last_error", "locked_at", "locked_by", "priority", "queue", "run_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["attempts", 0], ["created_at", Tue, 08 May 2012 12:14:15 UTC +00:00], ["failed_at", nil], ["handler", "--- !ruby/object:Delayed::PerformableMailer\nobject: !ruby/class 'InvitationMailer'\nmethod_name: :invite\nargs:\n- !ruby/ActiveRecord:Invitation\n attributes:\n id: 1\n sender_id: 1\n search_id: 1\n token: 4cba1a8a36de826493b1d8a8cc21091e2fb393e1\n sent_at: \n recipient_email: peter#example.com\n created_at: 2012-05-08 12:14:15.702071000 Z\n updated_at: 2012-05-08 12:14:15.702071000 Z\n recipient_id: \n accepted: \n"], ["last_error", nil], ["locked_at", nil], ["locked_by", nil], ["priority", 0], ["queue", nil], ["run_at", Tue, 08 May 2012 12:14:15 UTC +00:00], ["updated_at", Tue, 08 May 2012 12:14:15 UTC +00:00]]
(0.9ms) commit transaction
SQLite3::SQLException: cannot commit - no transaction is active: commit transaction
(0.5ms) rollback transaction
SQLite3::SQLException: cannot rollback - no transaction is active: rollback transaction
Completed 500 Internal Server Error in 126ms
SQL (1.9ms) UPDATE "delayed_jobs" SET locked_at = '2012-05-08 12:14:16.993126', locked_by = 'host:dtmbp.local pid:14059' WHERE (id = 3 and (locked_at is null or locked_at < '2012-05-08 08:14:16.993126') and (run_at <= '2012-05-08 12:14:16.993126'))
Invitation Load (0.2ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
Invitation Load (0.1ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
Invitation Load (0.1ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
Invitation Load (0.1ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
Invitation Load (0.1ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = ? LIMIT 1 [["id", 1]]
(0.1ms) begin transaction
(0.5ms) UPDATE "delayed_jobs" SET "locked_at" = '2012-05-08 12:14:16.993126', "locked_by" = 'host:dtmbp.local pid:14059', "last_error" = '{Delayed::DeserializationError
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/psych_ext.rb:108:in `rescue in visit_Psych_Nodes_Mapping_with_class''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/psych_ext.rb:101:in `visit_Psych_Nodes_Mapping_with_class''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:134:in `block in visit_Psych_Nodes_Sequence''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:134:in `each''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:134:in `visit_Psych_Nodes_Sequence''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:276:in `block in revive''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:276:in `map''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:276:in `revive''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:219:in `visit_Psych_Nodes_Mapping''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:231:in `visit_Psych_Nodes_Document''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/nodes/node.rb:35:in `to_ruby''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:128:in `load''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/backend/base.rb:84:in `payload_object''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/backend/base.rb:94:in `block in invoke_job''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/backend/base.rb:91:in `invoke_job''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:178:in `block (2 levels) in run''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:68:in `timeout''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:178:in `block in run''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:177:in `run''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:234:in `block in reserve_and_run_one_job''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:234:in `reserve_and_run_one_job''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:162:in `block in work_off''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:161:in `times''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:161:in `work_off''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:133:in `block (4 levels) in start''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:132:in `block (3 levels) in start''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:129:in `block (2 levels) in start''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:128:in `loop''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:128:in `block in start''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/plugins/clear_locks.rb:7:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:78:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:78:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:78:in `block in add''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:65:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/worker.rb:127:in `start''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/gems/delayed_job-3.0.2/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain''
/Users/davidtuite/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/bin/rake:19:in `load''
/Users/davidtuite/.rvm/gems/ruby-1.9.3-p194/bin/rake:19:in `<main>''', "failed_at" = '2012-05-08 12:14:17.131476', "updated_at" = '2012-05-08 12:14:17.132975' WHERE "delayed_jobs"."id" = 3
(1.5ms) commit transaction
I just had this error and realized that the AR object in question had simply already been deleted. Maybe that's your situation too?
Related link: psych_ext.rb#L101 breaks restoring of deleted serialized objects

Resources