简体   繁体   中英

Can delayed_jobs create delayed_jobs?

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?

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

我简单的测试呼叫send_later通过调用的方法send_later表明,NO,它不会工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM