module BatchKit::ActsAsJob
When included into a class, marks the class as a BatchKit
job. The including class has the following class methods added, which act as a DSL for specifying the job properties and behaviour:
-
{ClassMethods#desc desc} A method for setting a description for a subsequent job or task
-
{ClassMethods#job job} Defines a job entry method
-
{ClassMethods#task task} Defines a task method
-
{ClassMethods#job_definition job_definition} Returns the
Job::Definition
object for the including class -
{ClassMethods#on_success on_success} defines a callback to be called if the job completes successfully.
-
{ClassMethods#on_failure on_failure} defines a callback to be called if the job encounters an unhandled exception.
-
{ClassMethods#on_completion} defines a callback to be called when the job completes.
Instances of the including class also get the following instance methods:
-
{#job} Returns the
Job::Definition
for the class -
{#job_run} Returns the
Job::Run
associated with this object instance.
Public Class Methods
Hook used to extend the including class with class methods defined in the ActsAsJob::ClassMethods
module.
Creates a Job::Definition
object to hold details of the job, and stores it away in a @__job__ class instance variable.
# File lib/batch-kit/framework/acts_as_job.rb, line 173 def self.included(base) base.extend(ClassMethods) caller.find{ |f| !(f =~ /batch-kit.framework/) } =~ /^((?:[a-zA-Z]:)?[^:]+)/ job_file = File.realpath($1) job_defn = Job::Definition.new(base, job_file) base.instance_variable_set :@__job__, job_defn Events.publish(base, 'acts_as_job.included', job_defn) end
Public Instance Methods
@return [Job::Definition] The JobDefinition for this job instance.
# File lib/batch-kit/framework/acts_as_job.rb, line 184 def job self.class.job_definition end
@return [Job::Run] The JobRun for this job instance.
# File lib/batch-kit/framework/acts_as_job.rb, line 190 def job_run @__job_run__ end