Module: BatchKit::ActsAsJob
- Defined in:
- lib/batch-kit/framework/acts_as_job.rb
Overview
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:
-
desc A method for setting a description for a subsequent job or task
-
job Defines a job entry method
-
task Defines a task method
-
job_definition Returns the Job::Definition object for the including class
-
on_success defines a callback to be called if the job completes successfully.
-
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:
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Hook used to extend the including class with class methods defined in the ActsAsJob::ClassMethods module.
Instance Method Summary collapse
-
#job ⇒ Job::Definition
The JobDefinition for this job instance.
-
#job_run ⇒ Job::Run
The JobRun for this job instance.
Class Method Details
.included(base) ⇒ Object
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.
173 174 175 176 177 178 179 180 |
# 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 |
Instance Method Details
#job ⇒ Job::Definition
Returns The JobDefinition for this job instance.
184 185 186 |
# File 'lib/batch-kit/framework/acts_as_job.rb', line 184 def job self.class.job_definition end |
#job_run ⇒ Job::Run
Returns The JobRun for this job instance.
190 191 192 |
# File 'lib/batch-kit/framework/acts_as_job.rb', line 190 def job_run @__job_run__ end |