diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_job/arguments.rb | 24 | ||||
-rw-r--r-- | lib/active_job/enqueuing.rb | 6 | ||||
-rw-r--r-- | lib/active_job/parameters.rb | 24 | ||||
-rw-r--r-- | lib/active_job/performing.rb | 4 |
4 files changed, 29 insertions, 29 deletions
diff --git a/lib/active_job/arguments.rb b/lib/active_job/arguments.rb new file mode 100644 index 0000000000..d1cc6d3177 --- /dev/null +++ b/lib/active_job/arguments.rb @@ -0,0 +1,24 @@ +require 'active_model/global_locator' +require 'active_support/core_ext/object/try' + +module ActiveJob + class Arguments + TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Hash, Array, Bignum ] + + def self.serialize(arguments) + arguments.collect do |argument| + if argument.respond_to?(:global_id) + argument.global_id + elsif TYPE_WHITELIST.include?(argument.class) + argument + else + raise "Unsupported argument type: #{argument.class.name}" + end + end + end + + def self.deserialize(arguments) + arguments.collect { |argument| ActiveModel::GlobalLocator.locate(argument) || argument } + end + end +end diff --git a/lib/active_job/enqueuing.rb b/lib/active_job/enqueuing.rb index 8b1f29ce77..4ff7ec7e7f 100644 --- a/lib/active_job/enqueuing.rb +++ b/lib/active_job/enqueuing.rb @@ -1,4 +1,4 @@ -require 'active_job/parameters' +require 'active_job/arguments' module ActiveJob module Enqueuing @@ -15,7 +15,7 @@ module ActiveJob def enqueue(*args) new(args).tap do |job| job.run_callbacks :enqueue do - queue_adapter.enqueue self, *Parameters.serialize(args) + queue_adapter.enqueue self, *Arguments.serialize(args) end end end @@ -41,7 +41,7 @@ module ActiveJob job.enqueued_at = timestamp job.run_callbacks :enqueue do - queue_adapter.enqueue_at self, timestamp.to_f, *Parameters.serialize(args) + queue_adapter.enqueue_at self, timestamp.to_f, *Arguments.serialize(args) end end end diff --git a/lib/active_job/parameters.rb b/lib/active_job/parameters.rb deleted file mode 100644 index 955fd887d7..0000000000 --- a/lib/active_job/parameters.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'active_model/global_locator' -require 'active_support/core_ext/object/try' - -module ActiveJob - class Parameters - TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Hash, Array, Bignum ] - - def self.serialize(params) - params.collect do |param| - if param.respond_to?(:global_id) - param.global_id - elsif TYPE_WHITELIST.include?(param.class) - param - else - raise "Unsupported parameter type: #{param.class.name}" - end - end - end - - def self.deserialize(params) - params.collect { |param| ActiveModel::GlobalLocator.locate(param) || param } - end - end -end diff --git a/lib/active_job/performing.rb b/lib/active_job/performing.rb index 126193995c..ef17a39f85 100644 --- a/lib/active_job/performing.rb +++ b/lib/active_job/performing.rb @@ -1,9 +1,9 @@ -require 'active_job/parameters' +require 'active_job/arguments' module ActiveJob module Performing def perform_with_hooks(*serialized_args) - self.arguments = Parameters.deserialize(serialized_args) + self.arguments = Arguments.deserialize(serialized_args) run_callbacks :perform do perform *arguments |