Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

ruby - 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

This all works of course but there is a bit of a lag between calling perform_async and the job actually getting executed.

Is there anything else I can do to tell sidekiq to execute the job immediately?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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_interval setting:

Sidekiq.configure_server do |config|
  config.poll_interval = 2
end

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...