diff options
Diffstat (limited to 'lib/active_job')
-rw-r--r-- | lib/active_job/base.rb | 9 | ||||
-rw-r--r-- | lib/active_job/queue_adapter.rb | 24 |
2 files changed, 27 insertions, 6 deletions
diff --git a/lib/active_job/base.rb b/lib/active_job/base.rb index 86008d3c94..d3b0fcffa8 100644 --- a/lib/active_job/base.rb +++ b/lib/active_job/base.rb @@ -1,9 +1,11 @@ +require 'active_job/queue_adapter' require 'active_job/queue_adapters/inline_adapter' require 'active_support/core_ext/string/inflections' module ActiveJob class Base - cattr_accessor(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter } + extend QueueAdapter + cattr_accessor(:queue_base_name) { "active_jobs" } cattr_accessor(:queue_name) { queue_base_name } @@ -15,11 +17,6 @@ module ActiveJob def queue_as(part_name) self.queue_name = "#{queue_base_name}_#{part_name}" end - - def adapter=(adapter_name) - require "active_job/queue_adapters/#{adapter_name}_adapter" - ActiveJob::Base.queue_adapter = "ActiveJob::QueueAdapters::#{adapter_name.to_s.camelize}Adapter".constantize - end end end end
\ No newline at end of file diff --git a/lib/active_job/queue_adapter.rb b/lib/active_job/queue_adapter.rb new file mode 100644 index 0000000000..a1987a7dc3 --- /dev/null +++ b/lib/active_job/queue_adapter.rb @@ -0,0 +1,24 @@ +require 'active_job/queue_adapters/inline_adapter' +require 'active_support/core_ext/string/inflections' + +module ActiveJob + module QueueAdapter + mattr_reader(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter } + + def queue_adapter=(name_or_adapter) + if name_or_adapter.is_a?(Symbol) || name_or_adapter.is_a?(String) + adapter = load_adapter(name_or_adapter) + else + adapter = name_or_adapter + end + + @@queue_adapter = adapter + end + + private + def load_adapter(name) + require "active_job/queue_adapters/#{name}_adapter" + "ActiveJob::QueueAdapters::#{name.to_s.camelize}Adapter".constantize + end + end +end
\ No newline at end of file |