Class: Libis::Workflow::Task
- Inherits:
-
Object
- Object
- Libis::Workflow::Task
- Includes:
- Tools::Logger, Tools::ParameterContainer
- Defined in:
- lib/libis/workflow/task.rb
Overview
noinspection RubyTooManyMethodsInspection
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#processing_item ⇒ Object
Returns the value of attribute processing_item.
-
#workitem ⇒ Object
Returns the value of attribute workitem.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(_task) ⇒ Object
- #apply_options(opts) ⇒ Object
-
#initialize(parent, cfg = {}) ⇒ Task
constructor
A new instance of Task.
- #logger ⇒ Object
- #message(severity, msg, *args) ⇒ Object
- #namepath ⇒ Object
- #names ⇒ Object
- #run(item) ⇒ Object
Constructor Details
#initialize(parent, cfg = {}) ⇒ Task
Returns a new instance of Task.
29 30 31 32 33 34 |
# File 'lib/libis/workflow/task.rb', line 29 def initialize(parent, cfg = {}) @subitems_stopper = false @subtasks_stopper = false self.parent = parent configure cfg end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
18 19 20 |
# File 'lib/libis/workflow/task.rb', line 18 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
18 19 20 |
# File 'lib/libis/workflow/task.rb', line 18 def parent @parent end |
#processing_item ⇒ Object
Returns the value of attribute processing_item.
18 19 20 |
# File 'lib/libis/workflow/task.rb', line 18 def processing_item @processing_item end |
#workitem ⇒ Object
Returns the value of attribute workitem.
18 19 20 |
# File 'lib/libis/workflow/task.rb', line 18 def workitem @workitem end |
Class Method Details
.task_classes ⇒ Object
25 26 27 |
# File 'lib/libis/workflow/task.rb', line 25 def self.task_classes ObjectSpace.each_object(::Class).select {|klass| klass < self} end |
Instance Method Details
#<<(_task) ⇒ Object
36 37 38 |
# File 'lib/libis/workflow/task.rb', line 36 def <<(_task) raise Libis::WorkflowError, "Processing task '#{namepath}' is not allowed to have subtasks." end |
#apply_options(opts) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/libis/workflow/task.rb', line 112 def (opts) o = {} o.merge!(opts[self.class.to_s] || {}) o.merge!(opts[name] || opts[names.join('/')] || {}) if o && o.is_a?(Hash) default_values.each do |name, _| next unless o.key?(name.to_s) next if o[name.to_s].nil? paramdef = get_parameter_definition name.to_sym value = paramdef.parse(o[name.to_s]) parameter(name.to_sym, value) end end end |
#logger ⇒ Object
140 141 142 |
# File 'lib/libis/workflow/task.rb', line 140 def logger (parent || get_run).logger end |
#message(severity, msg, *args) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/libis/workflow/task.rb', line 128 def (severity, msg, *args) taskname = namepath rescue nil set_application(taskname) item = workitem rescue nil item = args.shift if args.size > 0 and args[0].is_a?(::Libis::Workflow::Base::WorkItem) subject = item.namepath rescue nil subject ||= item.name rescue nil subject ||= item.to_s rescue nil set_subject(subject) super(severity, msg, *args) end |
#namepath ⇒ Object
108 109 110 |
# File 'lib/libis/workflow/task.rb', line 108 def namepath names.join('/') end |
#names ⇒ Object
104 105 106 |
# File 'lib/libis/workflow/task.rb', line 104 def names (parent.names rescue []).push(name).compact end |
#run(item) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/libis/workflow/task.rb', line 41 def run(item) check_item_type ::Libis::Workflow::Base::WorkItem, item self.workitem = item case action when :retry if item.check_status(:DONE, namepath) debug 'Retry: skipping task %s because it has finished successfully.', item, namepath return item end when :failed return item else # type code here end (parameter(:retry_count) + 1).times do i = run_item(item) item = i if i.is_a?(Libis::Workflow::WorkItem) case item.status(namepath) when :DONE self.action = :run return item when :ASYNC_WAIT self.action = :retry when :ASYNC_HALT break when :FAILED break else return item end self.action = :retry sleep(parameter(:retry_interval)) end item.get_run.action = :failed return item rescue WorkflowError => e error e., item set_status item, :FAILED rescue WorkflowAbort => e set_status item, :FAILED raise e if parent rescue => e set_status item, :FAILED fatal_error "Exception occured: #{e.}", item debug e.backtrace.join("\n") ensure item.save! end |