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 = nil) ⇒ Object
- #version ⇒ Object
- #waiting? ⇒ Boolean
Constructor Details
#initialize(repo, workflow, attrs) ⇒ Process
Returns a new instance of Process.
6 7 8 9 10 11 12 13 14 |
# File 'lib/dor/workflow/process.rb', line 6 def initialize(repo, workflow, attrs) @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.
4 5 6 |
# File 'lib/dor/workflow/process.rb', line 4 def owner @owner end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
4 5 6 |
# File 'lib/dor/workflow/process.rb', line 4 def repo @repo end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
4 5 6 |
# File 'lib/dor/workflow/process.rb', line 4 def workflow @workflow end |
Instance Method Details
#archived? ⇒ Boolean
51 52 53 54 |
# File 'lib/dor/workflow/process.rb', line 51 def archived? return true if(@attrs['archived'] =~ /true$/i) return false end |
#attempts ⇒ Object
74 75 76 |
# File 'lib/dor/workflow/process.rb', line 74 def attempts @attrs['attempts'].to_i end |
#batch_limit ⇒ Object
38 |
# File 'lib/dor/workflow/process.rb', line 38 def batch_limit ; @attrs['batch_limit'] ; end |
#blocked? ⇒ Boolean
60 61 62 |
# File 'lib/dor/workflow/process.rb', line 60 def blocked? self.waiting? and (not self.prerequisite.nil?) and self.prerequisite.any? { |pr| (prq = self.owner[pr]) && (prq.error? or prq.blocked?) } end |
#completed? ⇒ Boolean
46 |
# File 'lib/dor/workflow/process.rb', line 46 def completed? ; self.status == 'completed' ; end |
#date_time ⇒ Object
49 |
# File 'lib/dor/workflow/process.rb', line 49 def date_time ;@attrs['datetime'] ; end |
#datetime ⇒ Object
78 79 80 |
# File 'lib/dor/workflow/process.rb', line 78 def datetime @attrs['datetime'] ? Time.parse(@attrs['datetime']) : nil end |
#elapsed ⇒ Object
82 83 84 |
# File 'lib/dor/workflow/process.rb', line 82 def elapsed @attrs['elapsed'].nil? ? nil : @attrs['elapsed'].to_f end |
#error? ⇒ Boolean
47 |
# File 'lib/dor/workflow/process.rb', line 47 def error? ; self.status == 'error' ; end |
#error_limit ⇒ Object
39 |
# File 'lib/dor/workflow/process.rb', line 39 def error_limit ; @attrs['error_limit'] ; end |
#error_message ⇒ Object
40 |
# File 'lib/dor/workflow/process.rb', line 40 def ; @attrs['errorMessage'] ; end |
#init_from_node(node) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dor/workflow/process.rb', line 16 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, 'prerequisite' => node.xpath('prereq').collect { |p| repo = (p['repository'].nil? or p['repository'] == @repo) ? nil : p['repository'] wf = (p['workflow'].nil? or p['workflow'] == @workflow) ? nil : p['workflow'] [repo,wf,p.text.to_s].compact.join(':') }, 'priority' => node['priority'] ? node['priority'].to_i : 0 } end |
#label ⇒ Object
37 |
# File 'lib/dor/workflow/process.rb', line 37 def label ; @attrs['label'] ; end |
#lifecycle ⇒ Object
36 |
# File 'lib/dor/workflow/process.rb', line 36 def lifecycle ; @attrs['lifecycle'] ; end |
#name ⇒ Object
34 |
# File 'lib/dor/workflow/process.rb', line 34 def name ; @attrs['name'] ; end |
#note ⇒ Object
43 |
# File 'lib/dor/workflow/process.rb', line 43 def note ; @attrs['note'] ; end |
#prerequisite ⇒ Object
41 |
# File 'lib/dor/workflow/process.rb', line 41 def prerequisite ; @attrs['prerequisite'] ; end |
#priority ⇒ Object
45 |
# File 'lib/dor/workflow/process.rb', line 45 def priority ; @attrs['priority'] ; end |
#ready? ⇒ Boolean
56 57 58 |
# File 'lib/dor/workflow/process.rb', line 56 def ready? self.waiting? and (not self.prerequisite.nil?) and self.prerequisite.all? { |pr| (prq = self.owner[pr]) && prq.completed? } end |
#sequence ⇒ Object
35 |
# File 'lib/dor/workflow/process.rb', line 35 def sequence ; @attrs['sequence'] ; end |
#state ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/dor/workflow/process.rb', line 64 def state if blocked? 'blocked' elsif ready? 'ready' else status end end |
#status ⇒ Object
42 |
# File 'lib/dor/workflow/process.rb', line 42 def status ; @attrs['status'] ; end |
#to_hash ⇒ Object
94 95 96 |
# File 'lib/dor/workflow/process.rb', line 94 def to_hash @attrs.reject { |k,v| v.nil? or v == 0 or (v.respond_to?(:empty?) and v.empty?) } end |
#update!(info, new_owner = nil) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/dor/workflow/process.rb', line 86 def update!(info, new_owner=nil) @owner = new_owner unless new_owner.nil? if info.is_a? Nokogiri::XML::Node info = Hash[info.attributes.collect { |k,v| [k,v.value] }] end @attrs.merge! info end |
#version ⇒ Object
44 |
# File 'lib/dor/workflow/process.rb', line 44 def version ; @attrs['version'] ; end |
#waiting? ⇒ Boolean
48 |
# File 'lib/dor/workflow/process.rb', line 48 def waiting? ; self.status == 'waiting' ; end |