aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activejob/lib')
-rw-r--r--activejob/lib/active_job/arguments.rb15
-rw-r--r--activejob/lib/active_job/queue_adapters/backburner_adapter.rb3
-rw-r--r--activejob/lib/active_job/queue_adapters/que_adapter.rb2
-rw-r--r--activejob/lib/rails/generators/job/job_generator.rb6
4 files changed, 20 insertions, 6 deletions
diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb
index 369e716912..e54f4afbc7 100644
--- a/activejob/lib/active_job/arguments.rb
+++ b/activejob/lib/active_job/arguments.rb
@@ -1,4 +1,7 @@
module ActiveJob
+ # Raised when an exception is raised during job arguments deserialization.
+ #
+ # Wraps the original exception raised as +original_exception+.
class DeserializationError < StandardError
attr_reader :original_exception
@@ -9,6 +12,14 @@ module ActiveJob
end
end
+ # Raised when an unsupported argument type is being set as job argument. We
+ # currently support NilClass, Fixnum, Float, String, TrueClass, FalseClass,
+ # Bignum and object that can be represented as GlobalIDs (ex: Active Record).
+ # Also raised if you set the key for a Hash something else than a string or
+ # a symbol.
+ class SerializationError < ArgumentError
+ end
+
module Arguments
extend self
TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ]
@@ -33,7 +44,7 @@ module ActiveJob
when Hash
Hash[ argument.map { |key, value| [ serialize_hash_key(key), serialize_argument(value) ] } ]
else
- raise "Unsupported argument type: #{argument.class.name}"
+ raise SerializationError.new("Unsupported argument type: #{argument.class.name}")
end
end
@@ -55,7 +66,7 @@ module ActiveJob
when String, Symbol
key.to_s
else
- raise "Unsupported hash key type: #{key.class.name}"
+ raise SerializationError.new("Unsupported hash key type: #{key.class.name}")
end
end
end
diff --git a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb
index 6fe2d4eb53..8d34155645 100644
--- a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb
+++ b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb
@@ -9,7 +9,8 @@ module ActiveJob
end
def enqueue_at(job, timestamp, *args)
- raise NotImplementedError
+ delay = Time.current.to_f - timestamp
+ Backburner::Worker.enqueue JobWrapper, [ job.name, *args ], queue: job.queue_name, delay: delay
end
end
diff --git a/activejob/lib/active_job/queue_adapters/que_adapter.rb b/activejob/lib/active_job/queue_adapters/que_adapter.rb
index 0b87deb4e0..9c84c74f83 100644
--- a/activejob/lib/active_job/queue_adapters/que_adapter.rb
+++ b/activejob/lib/active_job/queue_adapters/que_adapter.rb
@@ -9,7 +9,7 @@ module ActiveJob
end
def enqueue_at(job, timestamp, *args)
- raise NotImplementedError
+ JobWrapper.enqueue job.name, *args, queue: job.queue_name, run_at: Time.at(timestamp)
end
end
diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb
index 78a9c27606..979ffcb748 100644
--- a/activejob/lib/rails/generators/job/job_generator.rb
+++ b/activejob/lib/rails/generators/job/job_generator.rb
@@ -7,12 +7,14 @@ module Rails
class_option :queue, type: :string, default: 'default', desc: 'The queue name for the generated job'
+ check_class_collision suffix: 'Job'
+
+ hook_for :test_framework
+
def self.default_generator_root
File.dirname(__FILE__)
end
- check_class_collision suffix: 'Job'
-
def create_job_file
template 'job.rb', File.join('app/jobs', class_path, "#{file_name}_job.rb")
end