Class: Dor::Workflow::Process
- Inherits:
-
Object
- Object
- Dor::Workflow::Process
- Defined in:
- lib/dor/workflow/process.rb
Instance Attribute Summary collapse
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
Instance Method Summary collapse
- #archived? ⇒ Boolean
- #attempts ⇒ Object
- #batch_limit ⇒ Object
- #blocked? ⇒ Boolean
- #completed? ⇒ Boolean
- #date_time ⇒ Object
- #datetime ⇒ Object
- #elapsed ⇒ Object
- #error? ⇒ Boolean
- #error_limit ⇒ Object
- #error_message ⇒ Object
- #init_from_node(node) ⇒ Object
-
#initialize(repo, workflow, attrs) ⇒ Process
constructor
A new instance of Process.
- #label ⇒ Object
- #lifecycle ⇒ Object
- #name ⇒ Object
- #note ⇒ Object
- #prerequisite ⇒ Object
- #priority ⇒ Object
- #ready? ⇒ Boolean
- #sequence ⇒ Object
- #state ⇒ Object
- #status ⇒ Object
- #to_hash ⇒ Object
-
#update!(info, new_owner) ⇒ Object
Updates this object with the attributes passed in.
- #version ⇒ Object
- #waiting? ⇒ Boolean
Constructor Details
#initialize(repo, workflow, attrs) ⇒ Process
Returns a new instance of Process.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dor/workflow/process.rb', line 11 def initialize(repo, workflow, attrs) Deprecation.warn(self, 'Dor::Workflow::Process is deprecated and will be removed from dor-services version 9') @workflow = workflow @repo = repo if attrs.is_a? Nokogiri::XML::Node init_from_node(attrs) else @attrs = attrs end end |
Instance Attribute Details
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
6 7 8 |
# File 'lib/dor/workflow/process.rb', line 6 def owner @owner end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
6 7 8 |
# File 'lib/dor/workflow/process.rb', line 6 def repo @repo end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
6 7 8 |
# File 'lib/dor/workflow/process.rb', line 6 def workflow @workflow end |
Instance Method Details
#archived? ⇒ Boolean
104 105 106 |
# File 'lib/dor/workflow/process.rb', line 104 def archived? @attrs['archived'] =~ /true$/i end |
#attempts ⇒ Object
126 127 128 |
# File 'lib/dor/workflow/process.rb', line 126 def attempts @attrs['attempts'].to_i end |
#batch_limit ⇒ Object
56 57 58 |
# File 'lib/dor/workflow/process.rb', line 56 def batch_limit @attrs['batch_limit'] end |
#blocked? ⇒ Boolean
112 113 114 |
# File 'lib/dor/workflow/process.rb', line 112 def blocked? waiting? && !prerequisite.nil? && prerequisite.any? { |pr| (prq = owner[pr]) && (prq.error? || prq.blocked?) } end |
#completed? ⇒ Boolean
88 89 90 |
# File 'lib/dor/workflow/process.rb', line 88 def completed? status == 'completed' end |
#date_time ⇒ Object
100 101 102 |
# File 'lib/dor/workflow/process.rb', line 100 def date_time @attrs['datetime'] end |
#datetime ⇒ Object
130 131 132 |
# File 'lib/dor/workflow/process.rb', line 130 def datetime @attrs['datetime'] ? Time.parse(@attrs['datetime']) : nil end |
#elapsed ⇒ Object
134 135 136 |
# File 'lib/dor/workflow/process.rb', line 134 def elapsed @attrs['elapsed'].nil? ? nil : @attrs['elapsed'].to_f end |
#error? ⇒ Boolean
92 93 94 |
# File 'lib/dor/workflow/process.rb', line 92 def error? status == 'error' end |
#error_limit ⇒ Object
60 61 62 |
# File 'lib/dor/workflow/process.rb', line 60 def error_limit @attrs['error_limit'] end |
#error_message ⇒ Object
64 65 66 |
# File 'lib/dor/workflow/process.rb', line 64 def @attrs['errorMessage'] end |
#init_from_node(node) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dor/workflow/process.rb', line 22 def init_from_node(node) @attrs = { 'name' => node['name'], 'sequence' => node['sequence'] ? node['sequence'].to_i : nil, 'status' => node['status'], # TODO: see how this affects argo 'lifecycle' => node['lifecycle'], 'label' => node.at_xpath('label/text()').to_s, 'batch_limit' => node['batch-limit'] ? node['batch-limit'].to_i : nil, 'error_limit' => node['error-limit'] ? node['error-limit'].to_i : nil, 'priority' => node['priority'] ? node['priority'].to_i : 0, 'prerequisite' => node.xpath('prereq').collect do |p| repo = p['repository'].nil? || p['repository'] == @repo ? nil : p['repository'] wf = p['workflow'].nil? || p['workflow'] == @workflow ? nil : p['workflow'] [repo, wf, p.text.to_s].compact.join(':') end } end |
#label ⇒ Object
52 53 54 |
# File 'lib/dor/workflow/process.rb', line 52 def label @attrs['label'] end |
#lifecycle ⇒ Object
48 49 50 |
# File 'lib/dor/workflow/process.rb', line 48 def lifecycle @attrs['lifecycle'] end |
#name ⇒ Object
40 41 42 |
# File 'lib/dor/workflow/process.rb', line 40 def name @attrs['name'] end |
#note ⇒ Object
76 77 78 |
# File 'lib/dor/workflow/process.rb', line 76 def note @attrs['note'] end |
#prerequisite ⇒ Object
68 69 70 |
# File 'lib/dor/workflow/process.rb', line 68 def prerequisite @attrs['prerequisite'] end |
#priority ⇒ Object
84 85 86 |
# File 'lib/dor/workflow/process.rb', line 84 def priority @attrs['priority'] end |
#ready? ⇒ Boolean
108 109 110 |
# File 'lib/dor/workflow/process.rb', line 108 def ready? waiting? && !prerequisite.nil? && prerequisite.all? { |pr| (prq = owner[pr]) && prq.completed? } end |
#sequence ⇒ Object
44 45 46 |
# File 'lib/dor/workflow/process.rb', line 44 def sequence @attrs['sequence'] end |
#state ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/dor/workflow/process.rb', line 116 def state if blocked? 'blocked' elsif ready? 'ready' else status end end |
#status ⇒ Object
72 73 74 |
# File 'lib/dor/workflow/process.rb', line 72 def status @attrs['status'] end |
#to_hash ⇒ Object
152 153 154 |
# File 'lib/dor/workflow/process.rb', line 152 def to_hash @attrs.reject { |_k, v| v.nil? || v == 0 || (v.respond_to?(:empty?) && v.empty?) } end |
#update!(info, new_owner) ⇒ Object
Updates this object with the attributes passed in.
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/dor/workflow/process.rb', line 141 def update!(info, new_owner) raise ArgumentError, 'Owner can not be nil. It must be an instance of Dor::Workflow::Document' unless new_owner @owner = new_owner return self if info.nil? info = Hash[info.attributes.collect { |k, v| [k, v.value] }] if info.is_a? Nokogiri::XML::Node @attrs.merge! info self end |
#version ⇒ Object
80 81 82 |
# File 'lib/dor/workflow/process.rb', line 80 def version @attrs['version'] end |
#waiting? ⇒ Boolean
96 97 98 |
# File 'lib/dor/workflow/process.rb', line 96 def waiting? status == 'waiting' end |