Class: Dor::Workflow::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/workflow/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, workflow, attrs) ⇒ Process

Returns a new instance of Process.

Parameters:

  • repo (String)

    the name of the repository, typically ‘dor’

  • workflow (String)

    the name of the workflow, e.g. ‘assemblyWF’

  • attrs (Nokogiri::XML::Node, Hash)


11
12
13
14
15
16
17
18
19
# File 'lib/dor/workflow/process.rb', line 11

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

#ownerObject (readonly)

Returns the value of attribute owner.



6
7
8
# File 'lib/dor/workflow/process.rb', line 6

def owner
  @owner
end

#repoObject (readonly)

Returns the value of attribute repo.



6
7
8
# File 'lib/dor/workflow/process.rb', line 6

def repo
  @repo
end

#workflowObject (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

Returns:

  • (Boolean)


103
104
105
# File 'lib/dor/workflow/process.rb', line 103

def archived?
  @attrs['archived'] =~ /true$/i
end

#attemptsObject



125
126
127
# File 'lib/dor/workflow/process.rb', line 125

def attempts
  @attrs['attempts'].to_i
end

#batch_limitObject



55
56
57
# File 'lib/dor/workflow/process.rb', line 55

def batch_limit
  @attrs['batch_limit']
end

#blocked?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/dor/workflow/process.rb', line 111

def blocked?
  waiting? && !prerequisite.nil? && prerequisite.any? { |pr| (prq = owner[pr]) && (prq.error? || prq.blocked?) }
end

#completed?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/dor/workflow/process.rb', line 87

def completed?
  status == 'completed'
end

#date_timeObject



99
100
101
# File 'lib/dor/workflow/process.rb', line 99

def date_time
  @attrs['datetime']
end

#datetimeObject



129
130
131
# File 'lib/dor/workflow/process.rb', line 129

def datetime
  @attrs['datetime'] ? Time.parse(@attrs['datetime']) : nil
end

#elapsedObject



133
134
135
# File 'lib/dor/workflow/process.rb', line 133

def elapsed
  @attrs['elapsed'].nil? ? nil : @attrs['elapsed'].to_f
end

#error?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/dor/workflow/process.rb', line 91

def error?
  status == 'error'
end

#error_limitObject



59
60
61
# File 'lib/dor/workflow/process.rb', line 59

def error_limit
  @attrs['error_limit']
end

#error_messageObject



63
64
65
# File 'lib/dor/workflow/process.rb', line 63

def error_message
  @attrs['errorMessage']
end

#init_from_node(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dor/workflow/process.rb', line 21

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

#labelObject



51
52
53
# File 'lib/dor/workflow/process.rb', line 51

def label
  @attrs['label']
end

#lifecycleObject



47
48
49
# File 'lib/dor/workflow/process.rb', line 47

def lifecycle
  @attrs['lifecycle']
end

#nameObject



39
40
41
# File 'lib/dor/workflow/process.rb', line 39

def name
  @attrs['name']
end

#noteObject



75
76
77
# File 'lib/dor/workflow/process.rb', line 75

def note
  @attrs['note']
end

#prerequisiteObject



67
68
69
# File 'lib/dor/workflow/process.rb', line 67

def prerequisite
  @attrs['prerequisite']
end

#priorityObject



83
84
85
# File 'lib/dor/workflow/process.rb', line 83

def priority
  @attrs['priority']
end

#ready?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/dor/workflow/process.rb', line 107

def ready?
  waiting? && !prerequisite.nil? && prerequisite.all? { |pr| (prq = owner[pr]) && prq.completed? }
end

#sequenceObject



43
44
45
# File 'lib/dor/workflow/process.rb', line 43

def sequence
  @attrs['sequence']
end

#stateObject



115
116
117
118
119
120
121
122
123
# File 'lib/dor/workflow/process.rb', line 115

def state
  if blocked?
    'blocked'
  elsif ready?
    'ready'
  else
    status
  end
end

#statusObject



71
72
73
# File 'lib/dor/workflow/process.rb', line 71

def status
  @attrs['status']
end

#to_hashObject



151
152
153
# File 'lib/dor/workflow/process.rb', line 151

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.

Parameters:

Raises:

  • (ArgumentError)


140
141
142
143
144
145
146
147
148
149
# File 'lib/dor/workflow/process.rb', line 140

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

#versionObject



79
80
81
# File 'lib/dor/workflow/process.rb', line 79

def version
  @attrs['version']
end

#waiting?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/dor/workflow/process.rb', line 95

def waiting?
  status == 'waiting'
end