Can delayed_jobs create delayed_jobs?
-
22-09-2019 - |
Question
I'm trying to figure out if I'm able to use delayed_job
. I would need the ability to add jobs to the queue within a delayed_job
perform
method. Is this possible?
Solution
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's perform method (WIN)")
Proof.create!
end
end
from the console:
Delayed::Job.enqueue Machine.create!
This ends up creating an instance of Proof
and logs "Inside secondary's...".
OTHER TIPS
My simple test calling send_later
in a method invoked by send_later
indicates that NO, it will not work.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow