Why is work with a given job not delayed?

I deleted my example as much as possible. In my application, I create a dummy class and try to set the invocation method to the queue. This is added to the database perfectly, and with the_jobs delay running in the background, it selects it and updates it to lock. But actually it does not finish the job. It just stays in a locked state.

pry(main)> class DummyClass pry(main)* def self.call pry(main)* puts 'will this ever work?' pry(main)* end pry(main)* end => :call pry(main)> DummyClass.delay.call (0.2ms) BEGIN SQL (0.3ms) INSERT INTO `delayed_jobs` (`created_at`, `handler`, `queue`, `run_at`, `updated_at`) VALUES ('2014-12-19 12:11:40.006107', '--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/class \'DummyClass\'\nmethod_name: :call\nargs: []\n', 'default', '2014-12-19 12:11:40.005811', '2014-12-19 12:11:40.006107') (16.2ms) COMMIT => #<Delayed::Backend::ActiveRecord::Job:0x007fd0fdec0e20 id: 22, priority: 0, attempts: 0, handler: "--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/class 'DummyClass'\nmethod_name: :call\nargs: []\n", last_error: nil, run_at: Fri, 19 Dec 2014 14:11:40 CAT +02:00, locked_at: nil, failed_at: nil, locked_by: nil, queue: "default", created_at: Fri, 19 Dec 2014 14:11:40 CAT +02:00, updated_at: Fri, 19 Dec 2014 14:11:40 CAT +02:00> 

Blocks the task here

  SQL (0.8ms) UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_at` = '2014-12-19 12:17:20.031925', `delayed_jobs`.`locked_by` = 'delayed_job host:Ryan-Mes-MacBook-Pro-2.local pid:60080' WHERE ((run_at <= '2014-12-19 12:17:20.031003' AND (locked_at IS NULL OR locked_at < '2014-12-19 12:12:20.031154') OR locked_by = 'delayed_job host:Ryan-Mes-MacBook-Pro-2.local pid:60080') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 

Then it just freezes. I do not understand why such a simple task does not work.

Please note that this console is in my existing rails application. This may be an application configuration problem, but I could not find it.

Any ideas? I can try to give more information, but I think that is all.

The actual code I'm using is below

 module Events class ForwardRequestToPulse def self.call puts 'will this ever work' end end end class MyTestController < ApplicationController def index Events::ForwardRequestToPulse.delay.call end end 

The record is added to the delayed_jobs find table. When I run bin/delayed_job run , the record is blocked but not processed.

Below is an image of a locked record Locked record in database

+5
source share
2 answers

After scrolling in the gem, I narrowed down the problem to delayed_job, did not look for the locked records correctly. It included milliseconds in the filter for locked_at. mySql stores data without milliseconds, so it does not collect anything. After a bit more research into the gem in github delayed_job_active_record (I thought the problem was in me!) I found this fix . This solves my problem.

The reason this happened to me was because I was referring to the last stone 4.0.2 before this fix! Just my luck.

So, if you use 4.0.2 ... just update and it should disappear.

+1
source

I am more familiar with Sidekiq, but I think the problem is that you are defining the class to run in the rails console and the workers are launched in a separate process. Workers do not know about DummyClass and do not do this job. I recommend:

  • Make this class a Rails model (Dummy, etc.).
  • Restart delayed job
  • Insert an entry into the delayed_job table.
  • Check locked state
+4
source

Source: https://habr.com/ru/post/1209536/


All Articles