Module: Libis::Workflow::Base::Job
- Included in:
- Job
- Defined in:
- lib/libis/workflow/base/job.rb
Overview
This is the base module for Jobs.
This module lacks the implementation for the data attributes. It functions as an interface that describes the common functionality regardless of the storage implementation. These attributes require some implementation:
-
name: [String] the name of the Job. The name will be used to identify the job. Each time a job is executed,
a Run will be created for the associated workflow. The Run will get a name that starts with the job name and ends with the date and time the Run was first started. As such this name attribute serves as an identifier and should be treated as such. If possible it should be unique.
-
description: [String] optional information about the job.
-
workflow: [Object] the workflow containing the tasks that need to run.
-
run_obj: [String] the full class name of the Run implementation object that should be created when the
Job is executed.
-
input: [Hash] workflow input parameter values. Each input parameter of the workflow can be set by the entries
in this Hash.
A minimal in-memory implementation could be:
class Job
include ::Libis::Workflow::Base::Job
attr_accessor :name, :description, :workflow, :run_object, :input
def initialize
@name = ''
@description = ''
@input = Hash.new
@workflow = ::Libis::Workflow::Workflow.new
@run_object = ::Libis::Workflow::Run.new
end
end
Instance Method Summary collapse
- #configure(cfg = {}) ⇒ Object
-
#execute(opts = {}) ⇒ Object
noinspection RubyResolve.
- #run_name(timestamp = Time.now) ⇒ Object
Instance Method Details
#configure(cfg = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/libis/workflow/base/job.rb', line 47 def configure(cfg = {}) cfg.key_symbols_to_strings!(recursive: true) self.name ||= '' self.description ||= '' self.input ||= {} self.name = cfg['name'] if cfg.has_key?('name') self.description = cfg['description'] if cfg.has_key?('description') self.workflow = cfg['workflow'] if cfg.has_key?('workflow') self.run_object = cfg['run_object'] if cfg.has_key?('run_object') self.input.merge!(cfg['input'] || {}) end |
#execute(opts = {}) ⇒ Object
noinspection RubyResolve
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/libis/workflow/base/job.rb', line 61 def execute(opts = {}) run = self.create_run_object raise RuntimeError.new "Could not create instance of run object '#{self.run_object}'" unless run run.job = self (opts.delete('run_config') || {}).each { |key,value| run.send("#{key}=", value) } (opts.delete('run_properties') || {}).each { |key,value| run.properties[key] = value } run. = self.input.merge(opts) run.save! run.reload run.run run end |
#run_name(timestamp = Time.now) ⇒ Object
43 44 45 |
# File 'lib/libis/workflow/base/job.rb', line 43 def run_name( = Time.now) "#{self.name}-#{.strftime('%Y%m%d%H%M%S')}" end |