2017-07-09 13:49:52 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:40:03 -04:00
|
|
|
|
2016-08-06 12:40:07 -04:00
|
|
|
require "global_id/railtie"
|
|
|
|
require "active_job"
|
2014-05-21 16:45:56 -04:00
|
|
|
|
|
|
|
module ActiveJob
|
|
|
|
# = Active Job Railtie
|
|
|
|
class Railtie < Rails::Railtie # :nodoc:
|
2014-08-15 16:32:08 -04:00
|
|
|
config.active_job = ActiveSupport::OrderedOptions.new
|
2018-02-09 17:27:01 -05:00
|
|
|
config.active_job.custom_serializers = []
|
2014-08-15 16:32:08 -04:00
|
|
|
|
2016-08-06 12:40:07 -04:00
|
|
|
initializer "active_job.logger" do
|
2014-05-21 17:10:17 -04:00
|
|
|
ActiveSupport.on_load(:active_job) { self.logger = ::Rails.logger }
|
2014-05-21 16:45:56 -04:00
|
|
|
end
|
2014-08-15 16:32:08 -04:00
|
|
|
|
2018-02-09 17:27:01 -05:00
|
|
|
initializer "active_job.custom_serializers" do |app|
|
2018-02-15 01:46:42 -05:00
|
|
|
config.after_initialize do
|
|
|
|
custom_serializers = app.config.active_job.delete(:custom_serializers)
|
|
|
|
ActiveJob::Serializers.add_serializers custom_serializers
|
|
|
|
end
|
2018-02-09 17:27:01 -05:00
|
|
|
end
|
|
|
|
|
2014-08-15 16:32:08 -04:00
|
|
|
initializer "active_job.set_configs" do |app|
|
|
|
|
options = app.config.active_job
|
2016-02-05 10:05:48 -05:00
|
|
|
options.queue_adapter ||= :async
|
2014-08-15 16:32:08 -04:00
|
|
|
|
|
|
|
ActiveSupport.on_load(:active_job) do
|
2018-02-15 01:46:42 -05:00
|
|
|
options.each do |k, v|
|
|
|
|
k = "#{k}="
|
|
|
|
send(k, v) if respond_to? k
|
|
|
|
end
|
2014-08-15 16:32:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-26 00:47:01 -05:00
|
|
|
initializer "active_job.set_reloader_hook" do |app|
|
|
|
|
ActiveSupport.on_load(:active_job) do
|
|
|
|
ActiveJob::Callbacks.singleton_class.set_callback(:execute, :around, prepend: true) do |_, inner|
|
|
|
|
app.reloader.wrap do
|
|
|
|
inner.call
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-05-21 16:45:56 -04:00
|
|
|
end
|
2014-08-12 06:53:46 -04:00
|
|
|
end
|