2014-05-22 14:35:02 -04:00
|
|
|
require 'active_support/rescuable'
|
2014-05-22 13:35:45 -04:00
|
|
|
require 'active_job/arguments'
|
2014-05-20 18:26:19 -04:00
|
|
|
|
|
|
|
module ActiveJob
|
2014-05-22 14:37:06 -04:00
|
|
|
module Execution
|
2014-05-22 14:35:02 -04:00
|
|
|
extend ActiveSupport::Concern
|
2014-08-25 10:34:50 -04:00
|
|
|
include ActiveSupport::Rescuable
|
2014-05-30 19:19:30 -04:00
|
|
|
|
2014-11-03 22:23:36 -05:00
|
|
|
# Includes methods for executing and performing jobs instantly.
|
2014-08-25 10:34:50 -04:00
|
|
|
module ClassMethods
|
|
|
|
# Performs the job immediately.
|
|
|
|
#
|
|
|
|
# MyJob.perform_now("mike")
|
|
|
|
#
|
|
|
|
def perform_now(*args)
|
|
|
|
job_or_instantiate(*args).perform_now
|
|
|
|
end
|
2014-05-22 14:35:02 -04:00
|
|
|
|
2014-08-25 10:34:50 -04:00
|
|
|
def execute(job_data) #:nodoc:
|
|
|
|
job = deserialize(job_data)
|
|
|
|
job.perform_now
|
|
|
|
end
|
|
|
|
end
|
2014-05-22 13:33:23 -04:00
|
|
|
|
2014-08-25 10:34:50 -04:00
|
|
|
# Performs the job immediately. The job is not sent to the queueing adapter
|
2014-09-17 15:46:53 -04:00
|
|
|
# but directly executed by blocking the execution of others until it's finished.
|
2014-08-25 10:34:50 -04:00
|
|
|
#
|
|
|
|
# MyJob.new(*args).perform_now
|
|
|
|
def perform_now
|
|
|
|
deserialize_arguments_if_needed
|
2014-05-22 13:33:23 -04:00
|
|
|
run_callbacks :perform do
|
2014-08-15 06:11:58 -04:00
|
|
|
perform(*arguments)
|
2014-05-22 13:33:23 -04:00
|
|
|
end
|
2014-05-22 14:35:02 -04:00
|
|
|
rescue => exception
|
2014-05-22 19:14:13 -04:00
|
|
|
rescue_with_handler(exception) || raise(exception)
|
2014-05-20 18:26:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def perform(*)
|
2014-08-15 06:11:58 -04:00
|
|
|
fail NotImplementedError
|
2014-05-20 18:26:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|