views:

141

answers:

2

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?

A: 

My simple test calling send_later in a method invoked by send_later indicates that NO, it will not work.

Jonathan Julian
Perhaps it's just `send_later` that does not allow this. I tested in script/console.
Jonathan Julian
A: 

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...".

James
My delayed job also works fine at kicking off another delayed job as part of its operation.
Larry K