module Libis::Workflow::Base::Job

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:

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

Public Instance Methods

configure(cfg = {}) click to toggle source
# 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 = {}) click to toggle source

noinspection RubyResolve @param [Hash] opts optional extra conguration values for this particular run

# 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.options = self.input.merge(opts)
  run.save!
  run.reload

  run.run

  run
end
run_name(timestamp = Time.now) click to toggle source
# File lib/libis/workflow/base/job.rb, line 43
def run_name(timestamp = Time.now)
  "#{self.name}-#{timestamp.strftime('%Y%m%d%H%M%S')}"
end

Protected Instance Methods

create_run_object() click to toggle source

noinspection RubyResolve

# File lib/libis/workflow/base/job.rb, line 80
def create_run_object
  self.run_object.constantize.new
end