2015-12-31 15:33:35 -08:00
|
|
|
# frozen_string_literal: true
|
2018-12-07 17:59:42 +01:00
|
|
|
|
2019-07-24 10:52:54 -07:00
|
|
|
require "sidekiq/worker"
|
|
|
|
|
2012-01-25 13:32:51 -08:00
|
|
|
module Sidekiq
|
|
|
|
class Rails < ::Rails::Engine
|
2019-07-24 10:52:54 -07:00
|
|
|
# By including the Options module, we allow AJs to directly control sidekiq features
|
|
|
|
# via the *sidekiq_options* class method and, for instance, not use AJ's retry system.
|
|
|
|
# AJ retries don't show up in the Sidekiq UI Retries tab, save any error data, can't be
|
|
|
|
# manually retried, don't automatically die, etc.
|
|
|
|
#
|
|
|
|
# class SomeJob < ActiveJob::Base
|
|
|
|
# queue_as :default
|
|
|
|
# sidekiq_options retry: 3, backtrace: 10
|
|
|
|
# def perform
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
initializer "sidekiq.active_job_integration" do
|
|
|
|
ActiveSupport.on_load(:active_job) do
|
|
|
|
include ::Sidekiq::Worker::Options unless respond_to?(:sidekiq_options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This hook happens after all initializers are run, just before returning
|
|
|
|
# from config/environment.rb back to sidekiq/cli.rb.
|
|
|
|
# We have to add the reloader after initialize to see if cache_classes has
|
|
|
|
# been turned on.
|
|
|
|
#
|
|
|
|
# None of this matters on the client-side, only within the Sidekiq process itself.
|
2016-10-01 08:27:54 +10:00
|
|
|
config.after_initialize do
|
2016-12-12 09:39:12 -08:00
|
|
|
Sidekiq.configure_server do |_|
|
2018-12-28 10:16:50 -08:00
|
|
|
Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new
|
2016-10-01 08:27:54 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-01 15:59:20 -08:00
|
|
|
class Reloader
|
|
|
|
def initialize(app = ::Rails.application)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
2016-04-28 10:02:03 -07:00
|
|
|
@app.reloader.wrap do
|
|
|
|
yield
|
2016-02-01 15:59:20 -08:00
|
|
|
end
|
|
|
|
end
|
2016-04-28 10:38:46 -07:00
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<Sidekiq::Rails::Reloader @app=#{@app.class.name}>"
|
|
|
|
end
|
2016-02-01 15:59:20 -08:00
|
|
|
end
|
2018-12-28 10:16:50 -08:00
|
|
|
end
|
2018-12-07 17:59:42 +01:00
|
|
|
end
|