获取 sidekiq 立即执行作业 [英] Get sidekiq to execute a job immediately
问题描述
目前,我有一份这样的兼职工作:
At the moment, I have a sidekiq job like this:
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
这一切当然都有效,但在调用 perform_async 和实际执行作业之间存在一些滞后.
This all works of course but there is a bit of a lag between calling perform_async and the job actually getting executed.
我还能做些什么来告诉 sidekiq 立即执行作业吗?
Is there anything else I can do to tell sidekiq to execute the job immediately?
推荐答案
这里有两个问题.
如果要立即执行作业,可以在当前上下文中使用:
If you want to execute a job immediately, in the current context you can use:
SyncUser.new.perform(user.id)
如果您想减少调度异步工作与在 sidekiq 工作器中执行之间的延迟,您可以减少 poll_interval
设置:
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_interval
setting:
Sidekiq.configure_server do |config|
config.poll_interval = 2
end
poll_interval
是工作人员后端内工作人员检查队列中作业的频率的延迟.一个工作被调度到一个空闲工人执行之间的平均时间将为 poll_interval/2
.
The poll_interval
is 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
.
这篇关于获取 sidekiq 立即执行作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!