简体   繁体   English

并发延迟工作

[英]concurrency in delayed_jobs

I have ROR application and 1 delay_job process ran using rake job:work. 我有ROR应用程序,并且使用rake job:work运行了1个delay_job进程。 ROR application add Job in multiple queue. ROR应用程序将Job添加到多个队列中。

Lets say we have queue 1 and queue 2. 假设我们有队列1和队列2。
My Question is task in queue 1 and task in queue 2 will be executed concurrently? 我的问题是队列1中的任务和队列2中的任务将同时执行吗?

Currently in my application after running rake job:work process only 1 thread is spawn which executes queue1 task and then queue2 task. 当前在我的应用程序中运行rake job:work进程后,仅产生1个线程,该线程先执行queue1任务,然后执行queue2任务。
If i have to execute in parallel, i have to run two rake task of job:work. 如果必须并行执行,则必须运行job:work的两个rake任务。

Is it correct behavior or it can be run concurrently in 1 rake task of job:work. 它是正确的行为,还是可以在job:work的1个rake任务中同时运行。 And what is worker in Delay Job. 什么是延迟工作中的工人。 Is delay Job interchangeably used with worker 延迟工作与工人互换使用

Thanks 谢谢
Priyanka 普里扬卡

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). 在您描述的示例中,您正在启动一个在前台运行的rake job:workrake job:work ),但是您可以做的是通过运行bin/delayed_job来代替它们作为后台工作程序( script/delayed_job对于早期版本)。 That command has multiple options that you can use to specify how you want delayed_job to function. 该命令具有多个选项,可用于指定您希望delay_job起作用的方式。

One of the options is -n or --number_of_workers=workers . 选项之一是-n--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. 也可以将某些工作人员专用于仅运行特定队列中的作业,或者仅运行高优先级的作业。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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