Search code examples
ruby-on-railsrubydelayed-job

Delayed Job One worker for one task (synchronous call)


I have 20 Delayed job workers

I had search so many links and post for synchronous processing for that job but nothing works for me

Also assign QUEUE for perticular worker like this

script/delayed_job --queue=order_item_kit start -i 0

order.delay(:queue => "order_item_kit").update_order But this will assign to this queue and other worker also works for it.

I am searching for one worker will run one job at a time. for this particular case

Please give suggestion to work for this case, one method calls only one worker as a time.

Thanks in advance.


Solution

  • I can solve this by doing that way

    When it assign next same job to another worker, we can add run_at one second ahead, so multiple workers does not save object same time and this fix our issue

    latest_job = Delayed::Job.where(queue: "order_item_kit").last
    
    run_at = latest_job ? latest_job.run_at + 1.seconds : 1.seconds.from_now
    
    kit_sku.delay(:run_at => run_at,:queue =>"order_item_kit").update_ordere_item