aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activejob/lib')
-rw-r--r--activejob/lib/active_job.rb3
-rw-r--r--activejob/lib/active_job/arguments.rb15
-rw-r--r--activejob/lib/active_job/callbacks.rb4
-rw-r--r--activejob/lib/active_job/logging.rb8
-rw-r--r--activejob/lib/active_job/queue_adapter.rb1
-rw-r--r--activejob/lib/active_job/queue_adapters.rb16
-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/active_job/version.rb2
-rw-r--r--activejob/lib/rails/generators/job/job_generator.rb6
10 files changed, 45 insertions, 15 deletions
diff --git a/activejob/lib/active_job.rb b/activejob/lib/active_job.rb
index ef92406725..29123170b8 100644
--- a/activejob/lib/active_job.rb
+++ b/activejob/lib/active_job.rb
@@ -30,4 +30,5 @@ module ActiveJob
extend ActiveSupport::Autoload
autoload :Base
-end \ No newline at end of file
+ autoload :QueueAdapters
+end
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/callbacks.rb b/activejob/lib/active_job/callbacks.rb
index af92031bc9..cafa3438c0 100644
--- a/activejob/lib/active_job/callbacks.rb
+++ b/activejob/lib/active_job/callbacks.rb
@@ -3,8 +3,8 @@ require 'active_support/callbacks'
module ActiveJob
# = Active Job Callbacks
#
- # Active Job provides hooks during the lifecycle of a job. Callbacks allows you to trigger
- # logic during the lifecycle of a job. Available callbacks:
+ # Active Job provides hooks during the lifecycle of a job. Callbacks allow you
+ # to trigger logic during the lifecycle of a job. Available callbacks are:
#
# * <tt>before_enqueue</tt>
# * <tt>around_enqueue</tt>
diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb
index d9e544acf5..ae098a80f3 100644
--- a/activejob/lib/active_job/logging.rb
+++ b/activejob/lib/active_job/logging.rb
@@ -52,19 +52,19 @@ module ActiveJob
class LogSubscriber < ActiveSupport::LogSubscriber
def enqueue(event)
- info "Enqueued #{event.payload[:job].name} (Job ID: #{event.payload[:job_id]}) to #{queue_name(event)}" + args_info(event)
+ info { "Enqueued #{event.payload[:job].name} (Job ID: #{event.payload[:job_id]}) to #{queue_name(event)}" + args_info(event) }
end
def enqueue_at(event)
- info "Enqueued #{event.payload[:job].name} (Job ID: #{event.payload[:job_id]}) to #{queue_name(event)} at #{enqueued_at(event)}" + args_info(event)
+ info { "Enqueued #{event.payload[:job].name} (Job ID: #{event.payload[:job_id]}) to #{queue_name(event)} at #{enqueued_at(event)}" + args_info(event) }
end
def perform_start(event)
- info "Performing #{event.payload[:job].name} from #{queue_name(event)}" + args_info(event)
+ info { "Performing #{event.payload[:job].name} from #{queue_name(event)}" + args_info(event) }
end
def perform(event)
- info "Performed #{event.payload[:job].name} from #{queue_name(event)} in #{event.duration.round(2).to_s}ms"
+ info { "Performed #{event.payload[:job].name} from #{queue_name(event)} in #{event.duration.round(2).to_s}ms" }
end
private
diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb
index 8f2f8b86ea..13c23abce4 100644
--- a/activejob/lib/active_job/queue_adapter.rb
+++ b/activejob/lib/active_job/queue_adapter.rb
@@ -17,7 +17,6 @@ module ActiveJob
private
def load_adapter(name)
- require "active_job/queue_adapters/#{name}_adapter"
"ActiveJob::QueueAdapters::#{name.to_s.camelize}Adapter".constantize
end
end
diff --git a/activejob/lib/active_job/queue_adapters.rb b/activejob/lib/active_job/queue_adapters.rb
new file mode 100644
index 0000000000..007068ff0a
--- /dev/null
+++ b/activejob/lib/active_job/queue_adapters.rb
@@ -0,0 +1,16 @@
+module ActiveJob
+ module QueueAdapters
+ extend ActiveSupport::Autoload
+
+ autoload :InlineAdapter
+ autoload :BackburnerAdapter
+ autoload :DelayedJobAdapter
+ autoload :QuAdapter
+ autoload :QueAdapter
+ autoload :QueueClassicAdapter
+ autoload :ResqueAdapter
+ autoload :SidekiqAdapter
+ autoload :SneakersAdapter
+ autoload :SuckerPunchAdapter
+ 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..8ebee36e45 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 = timestamp - Time.current.to_f
+ 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/active_job/version.rb b/activejob/lib/active_job/version.rb
index 7e646fa3c4..971ba9fe0c 100644
--- a/activejob/lib/active_job/version.rb
+++ b/activejob/lib/active_job/version.rb
@@ -1,7 +1,7 @@
require_relative 'gem_version'
module ActiveJob
- # Returns the version of the currently loaded ActiveJob as a <tt>Gem::Version</tt>
+ # Returns the version of the currently loaded Active Job as a <tt>Gem::Version</tt>
def self.version
gem_version
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