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)


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

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.



4
5
6
# File 'lib/dor/workflow/process.rb', line 4

def owner
  @owner
end

#repoObject (readonly)

Returns the value of attribute repo.



4
5
6
# File 'lib/dor/workflow/process.rb', line 4

def repo
  @repo
end

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

Returns:

  • (Boolean)


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

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

#attemptsObject



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

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

#batch_limitObject



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

def batch_limit   ; @attrs['batch_limit']  ; end

#blocked?Boolean

Returns:

  • (Boolean)


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

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

#completed?Boolean

Returns:

  • (Boolean)


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

def completed?    ; status == 'completed'  ; end

#date_timeObject



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

def date_time     ; @attrs['datetime']     ; end

#datetimeObject



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

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

#elapsedObject



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

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

#error?Boolean

Returns:

  • (Boolean)


50
# File 'lib/dor/workflow/process.rb', line 50

def error?        ; status == 'error'      ; end

#error_limitObject



42
# File 'lib/dor/workflow/process.rb', line 42

def error_limit   ; @attrs['error_limit']  ; end

#error_messageObject



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

def error_message ; @attrs['errorMessage'] ; end

#init_from_node(node) ⇒ Object



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

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 { |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

#labelObject



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

def label         ; @attrs['label']        ; end

#lifecycleObject



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

def lifecycle     ; @attrs['lifecycle']    ; end

#nameObject



37
# File 'lib/dor/workflow/process.rb', line 37

def name          ; @attrs['name']         ; end

#noteObject



46
# File 'lib/dor/workflow/process.rb', line 46

def note          ; @attrs['note']         ; end

#prerequisiteObject



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

def prerequisite  ; @attrs['prerequisite'] ; end

#priorityObject



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

def priority      ; @attrs['priority']     ; end

#ready?Boolean

Returns:

  • (Boolean)


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

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

#sequenceObject



38
# File 'lib/dor/workflow/process.rb', line 38

def sequence      ; @attrs['sequence']     ; end

#stateObject



66
67
68
69
70
71
72
73
74
# File 'lib/dor/workflow/process.rb', line 66

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

#statusObject



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

def status        ; @attrs['status']       ; end

#to_hashObject



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

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)


91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dor/workflow/process.rb', line 91

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?

  if info.is_a? Nokogiri::XML::Node
    info = Hash[info.attributes.collect { |k, v| [k, v.value] }]
  end
  @attrs.merge! info
  self
end

#versionObject



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

def version       ; @attrs['version']      ; end

#waiting?Boolean

Returns:

  • (Boolean)


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

def waiting?      ; status == 'waiting'    ; end