Search code examples
ruby-on-railsdelayed-job

concurrency in delayed_jobs


I have ROR application and 1 delay_job process ran using rake job:work. ROR application add Job in multiple queue.

Lets say we have queue 1 and queue 2.
My Question is task in queue 1 and task in queue 2 will be executed concurrently?

Currently in my application after running rake job:work process only 1 thread is spawn which executes queue1 task and then queue2 task.
If i have to execute in parallel, i have to run two rake task of job:work.

Is it correct behavior or it can be run concurrently in 1 rake task of job:work. And what is worker in Delay Job. Is delay Job interchangeably used with worker

Thanks
Priyanka


Solution

  • No, one worker cannot run two jobs concurrently, you need more than one process running for that.

    In the example you are describing, you are starting a worker that is running in the foreground (rake job:work), but what you could do instead, is to start them as background workers, by running bin/delayed_job instead (script/delayed_job for earlier versions). That command has multiple options that you can use to specify how you want delayed_job to function.

    One of the options is -n or --number_of_workers=workers. That means you can start two workers by running the following command:

    bundle exec bin/delayed_job --number_of_workers=2 start
    

    It is also possible to dedicate certain workers to only run jobs from a specific queue, or only high priority jobs.