Disable automatic retry with ActiveJob, used with Sidekiq

后端 未结 6 1015
名媛妹妹
名媛妹妹 2021-02-03 23:58

Is there a way to disable automatic retry with ActiveJob and Sidekiq ?

I know that with Sidekiq only, we just have to put

sidekiq_options :retry => f         


        
6条回答
  •  别跟我提以往
    2021-02-04 00:31

    If you want to disable retry (or add any other Sidekiq options) for ActiveJob from gems (like for ActionMailbox::RoutingJob), you can use this approach (Rails 6.0.2+).

    1) Create a module with the desired Sidekiq options (using ActiveSupport::Concern)

    # lib/fixes/action_mailbox_routing_job_sidekiq_fix.rb
    
    module ActionMailboxRoutingJobSidekiqFix
      extend ActiveSupport::Concern
    
      included do
        sidekiq_options retry: false
      end
    end
    

    2) Include it in the job class in an initializer.

    # config/initializers/extensions.rb
    
    require Rails.root.join('lib', 'fixes', 'action_mailbox_routing_job_sidekiq_fix')
    
    Rails.configuration.to_prepare do
      ActionMailbox::RoutingJob.include ::ActionMailboxRoutingJobSidekiqFix
    end
    
    

提交回复
热议问题