Get sidekiq to execute a job immediately

前端 未结 2 364
不思量自难忘°
不思量自难忘° 2020-12-09 01:39

At the moment, I have a sidekiq job like this:

class SyncUser
  include Sidekiq::Worker

  def perform(user_id)
    #do stuff
  end
end

I a

相关标签:
2条回答
  • 2020-12-09 02:00

    Use SyncUser.perform_now(user.id)

    0 讨论(0)
  • 2020-12-09 02:06

    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.

    0 讨论(0)
提交回复
热议问题