ruby 获取 sidekiq 立即执行作业
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19251976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get sidekiq to execute a job immediately
提问by dagda1
At the moment, I have a sidekiq job like this:
目前,我有一个像这样的 sidekiq 工作:
class SyncUser
include Sidekiq::Worker
def perform(user_id)
#do stuff
end
end
I am placing a job on the queue like this:
我正在像这样在队列中放置一个工作:
SyncUser.perform_async user.id
This all works of course but there is a bit of a lag between calling perform_async and the job actually getting executed.
当然,这一切都有效,但在调用 perform_async 和实际执行作业之间存在一些滞后。
Is there anything else I can do to tell sidekiq to execute the job immediately?
我还能做些什么来告诉 sidekiq 立即执行作业吗?
回答by Winfield
There are two questions here.
这里有两个问题。
If you want to execute a job immediately, in the current context you can use:
如果要立即执行作业,可以在当前上下文中使用:
SyncUser.new.perform(user.id)
If you want to decrease the delay between asynchronous work being scheduled and when it's executed in the sidekiq worker, you can decrease the poll_intervalsetting:
如果要减少调度异步工作与其在 sidekiq 工作器中执行之间的延迟,可以减少poll_interval设置:
Sidekiq.configure_server do |config|
config.poll_interval = 2
end
The poll_intervalis the delay within worker backends of how frequently workers check for jobs on the queue. The average time between a job being scheduled and executed with a free worker will be poll_interval / 2.
这poll_interval是工作人员后端中工作人员检查队列中作业的频率的延迟。一个工作被安排到一个空闲工人执行之间的平均时间将为poll_interval / 2.

