Can delayed_jobs create delayed_jobs?

I am trying to figure out if I can use delayed_job. I would need the ability to add jobs to a queue in a method delayed_job perform. Is it possible?

+3
source share
2 answers

According to my test, they can:

model Machine:

class Machine < ActiveRecord::Base
  def perform
    Delayed::Job.enqueue Secondary.create!
  end
end

model Secondary:

class Secondary < ActiveRecord::Base
  def perform
    logger.info("Inside secondary perform method (WIN)")
    Proof.create!
  end
end

from the console:

Delay :: Job.enqueue Machine.create!

As a result, an instance Proofand the magazines "Internal secondary ..." are created.

+2
source

My simple call send_laterin the method called send_laterindicates that NO, it will not work.

-1
source

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


All Articles