Sidekiq 的民主队列 [英] Democratic queue in Sidekiq

查看:46
本文介绍了Sidekiq 的民主队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户可以创建一个包含多个任务的Project 对象.当用户告诉项目 execute 所有这些任务都放在 Sidekiq 的默认队列中.

Users can create a Project object that contain multiple tasks. When user tells the project to execute all those tasks are put on the default queue from Sidekiq.

问题是:如果用户创建一个包含 1000 个任务的项目并点击 execute 按钮,所有这 1000 个任务都会被放入队列中.如果在这之后,另一个用户创建了一个只有一个任务的项目,当他点击执行这个项目时,它的唯一任务被放在行尾.

The problem is: if a user creates a project with 1000 tasks and hit the execute buttom, all those 1000 tasks are put in queue. If just after that, another user creates a project with only one task, when he hits executes this project, its only task is put on the end of the line.

我希望后台进程以更民主的方式工作.如果每个项目都有自己的队列,那么第二个项目中的一项任务很可能会在 1000 个任务队列结束之前执行.

I'd like that background process to work on a more democratic way. If each project has its own queue, chances are that the one task from the second project is executed before the end of the 1000 tasks queue.

为此,我需要为每个项目单独创建队列,并且应该动态创建.我正在尝试使用以下代码而不是 perform_async 来实现这一点:

To do so, I will need separe queues for each project, and it should be dynamically created. I'm trying to accomplish that using the following instead of perform_async:

Sidekiq::Client.push('queue' => "project_#{self.project.id}", 'class' => TaskWorker, 'args' => [self.id])

然而,当我尝试执行一个项目时,所有任务都被放置在一个名为project_somenumber"的队列中,但没有一个被执行.看来,当我使用Sidekiq::Client.push 时,我需要告诉队列开始执行.这是正确的吗?我如何启动那个队列?

However, when I try to execute a project, all the tasks are placed in a queue called "project_somenumber" but none of them is executed. It seems that when I use Sidekiq::Client.push, I need to tell the queue to start executing. Is it correct? How can I start that queue?

推荐答案

Sidekiq 不支持动态队列名称.当您启动 Sidekiq 时,您可以使用sidekiq -q queue1 -q queue2 ..."告诉它要处理哪些队列,请参阅 Sidekiq 的高级选项 wiki 页面了解更多详情.

Sidekiq doesn't support dynamic queue names. When you start Sidekiq, you tell it which queues to process with "sidekiq -q queue1 -q queue2 ..." Please see Sidekiq's Advanced Options wiki page for more detail.

这篇关于Sidekiq 的民主队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆