Class: RobotMaster::Workflow

Inherits:
Object
  • Object
show all
Defined in:
lib/robot-master/workflow.rb

Overview

Manages a workflow to enqueue jobs into a priority queue

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, workflow, xml = nil) ⇒ Workflow

Returns a new instance of Workflow

Parameters:

  • repository (String)
  • workflow (String)
  • workflow (String)

    definition XML

Raises:

  • (Exception)

    if cannot read workflow configuration


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/robot-master/workflow.rb', line 52

def initialize(repository, workflow, xml = nil)
  @repository = repository
  @workflow = workflow
  
  # fetch the workflow object from our configuration cache
  if xml.nil?
    fn = "config/workflows/#{@repository}/#{@workflow}.xml"
    ROBOT_LOG.debug { "Reading #{fn}" }
    xml = File.read(fn)
  end
  @config = begin
    Nokogiri::XML(xml)
  rescue Exception => e
    ROBOT_LOG.error("Cannot load workflow object: #{fn}")
    raise e
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


6
7
8
# File 'lib/robot-master/workflow.rb', line 6

def config
  @config
end

#repositoryObject (readonly)

Returns the value of attribute repository


6
7
8
# File 'lib/robot-master/workflow.rb', line 6

def repository
  @repository
end

#workflowObject (readonly)

Returns the value of attribute workflow


6
7
8
# File 'lib/robot-master/workflow.rb', line 6

def workflow
  @workflow
end

Class Method Details

.assert_qualified(step) ⇒ Object

Parameters:

  • step (String)

    fully qualified step name

Raises:

  • (ArgumentError)

    if `step` is not fully qualified


34
35
36
# File 'lib/robot-master/workflow.rb', line 34

def self.assert_qualified(step)
  raise ArgumentError, "step not qualified: #{step}" unless qualified?(step)
end

.parse_qualified(step) ⇒ Array

Returns the repository, workflow, and step values

Examples:

parse_qualified("dor:assemblyWF:jp2-create")
=> ['dor', 'assemblyWF', 'jp2-create']

Parameters:

  • step (String)

    fully qualified step name

Returns:

  • (Array)

    the repository, workflow, and step values


43
44
45
46
# File 'lib/robot-master/workflow.rb', line 43

def self.parse_qualified(step)
  assert_qualified(step)
  step.split(/:/, 3)
end

.perform(repository, workflow) ⇒ RobotMaster::Workflow

Perform workflow queueing on the given workflow

Parameters:

  • repository (String)
  • workflow (String)

Returns:


13
14
15
16
17
18
19
# File 'lib/robot-master/workflow.rb', line 13

def self.perform(repository, workflow)
  start = Time.now
  ROBOT_LOG.debug { "Start Workflow.perform(#{repository}, #{workflow})" }
  master = new(repository, workflow)
  master.perform
  ROBOT_LOG.debug { "Finished Workflow.perform(#{repository}, #{workflow}): #{Time.now - start} seconds" }
end

.qualified?(step) ⇒ Boolean

like dor:assemblyWF:jp2-create

Examples:

qualified?("dor:assemblyWF:jp2-create")
=> true
qualified?("jp2-create")
=> false

Returns:

  • (Boolean)

    true if step is a qualified name,


28
29
30
# File 'lib/robot-master/workflow.rb', line 28

def self.qualified?(step)
  /^\w+:\w+:[\w\-]+$/ === step
end

Instance Method Details

#performRobotMaster::Workflow

Queries the workflow service for all druids awaiting processing, and queues them into a priority queue.

Returns:


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/robot-master/workflow.rb', line 73

def perform      
  # perform on each process step
  @config.xpath('//process').each do |node|        
    process = parse_process_node(node)
    
    # skip any processes that do not require queueing
    if process[:skip]
      ROBOT_LOG.debug { "Skipping #{process[:name]}" }
      next
    end
    
    # doit
    n = perform_on_process(process)
    ROBOT_LOG.info("Queued #{n} jobs for #{process[:name]}") if n > 0
  end
  self
end