Run Delayed Jobs and Sidekiq at the same time

后端 未结 3 1384
说谎
说谎 2020-12-31 06:24

I currently use delayed job to process jobs asynchronously. Instead of creating workers, I use the .delay method a lot.

I want to move to Sidekiq, but I

3条回答
  •  -上瘾入骨i
    2020-12-31 06:42

    For Sidekiq 2.17.1 and later, somewhere in the Rails initializers, call the following:

    Sidekiq.hook_rails!
    Sidekiq.remove_delay!
    

    and you will have only prefixed sidekiq_delay methods and so on.

    (official document)


    For older versions of Sidekiq:

    Put the following in config/initializers/sidekiq.rb

    module Sidekiq::Extensions::Klass
      alias :sidekiq_delay :delay
      remove_method :delay
      alias :sidekiq_delay_for :delay_for
      remove_method :delay_for
      alias :sidekiq_delay_until :delay_until
      remove_method :delay_until
    end
    
    module Sidekiq::Extensions::ActiveRecord
      alias :sidekiq_delay :delay
      remove_method :delay
      alias :sidekiq_delay_for :delay_for
      remove_method :delay_for
      alias :sidekiq_delay_until :delay_until
      remove_method :delay_until
    end
    
    module Sidekiq::Extensions::ActionMailer
      alias :sidekiq_delay :delay
      remove_method :delay
      alias :sidekiq_delay_for :delay_for
      remove_method :delay_for
      alias :sidekiq_delay_until :delay_until
      remove_method :delay_until
    end
    

    And then you can use sidekiq_delay to queue in Sidekiq, and call delay to queue in Delayed Job.

提交回复
热议问题