Class: Dor::Workflow::Client::Queues

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

Overview

Makes requests relating to the workflow queues

Instance Method Summary collapse

Constructor Details

#initialize(requestor:) ⇒ Queues

Returns a new instance of Queues.



8
9
10
# File 'lib/dor/workflow/client/queues.rb', line 8

def initialize(requestor:)
  @requestor = requestor
end

Instance Method Details

#lane_ids(workflow, process) ⇒ Array<String>

Returns all the distinct laneIds for a given workflow step

Parameters:

  • workflow (String)

    name

  • process (String)

    name

Returns:

  • (Array<String>)

    all of the distinct laneIds. Array will be empty if no lane ids were found



17
18
19
20
21
# File 'lib/dor/workflow/client/queues.rb', line 17

def lane_ids(workflow, process)
  uri = "workflow_queue/lane_ids?step=#{workflow}:#{process}"
  doc = Nokogiri::XML(requestor.request(uri))
  doc.xpath('/lanes/lane').map { |n| n['id'] }
end

#objects_erroring_at_workstep(error, options = {}) ⇒ Array<String>

Returns a list of druids from the workflow service that meet the criteria of the passed in error param

Parameters:

  • error (String)

    name of the error step

  • options (Hash) (defaults to: {})
  • options (String) (defaults to: {})

    :default_workflow workflow to query for if not using the qualified format

Options Hash (options):

  • :limit (Integer)

    maximum number of druids to return (nil for no limit)

Returns:

  • (Array<String>)

    Array of druids

See Also:

  • Dor::Workflow::Client::Queues.``#objects_for_workstep`


93
94
95
96
97
98
99
100
# File 'lib/dor/workflow/client/queues.rb', line 93

def objects_erroring_at_workstep(error, options = {})
  uri_string = "workflow_queue?error=#{error}"
  uri_string += "&limit=#{options[:limit].to_i}" if options[:limit]&.to_i&.positive?

  resp = requestor.request uri_string

  Nokogiri::XML(resp).xpath('//object[@id]').map { |n| n[:id] }
end

#objects_for_workstep(completed, waiting, lane_id = 'default', options = {}) ⇒ Array<String>

Returns a list of druids from the workflow service that meet the criteria of the passed in completed and waiting params

Examples:

objects_for_workstep(...)
=> [
   "druid:py156ps0477",
   "druid:tt628cb6479",
   "druid:ct021wp7863"
 ]
objects_for_workstep(..., "lane1")
=> {
 "druid:py156ps0477",
 "druid:tt628cb6479",
}
objects_for_workstep(..., "lane1", limit: 1)
=> {
 "druid:py156ps0477",
}

Parameters:

  • completed (Array<String>, String)

    An array or single String of the completed steps, should use the qualified format: workflow:step-name

  • waiting (String)

    name of the waiting step

  • workflow (String)

    default workflow to use if it isn't passed in the qualified-step-name

  • lane_id (String) (defaults to: 'default')

    issue a query for a specific lane_id for the waiting step

  • options (Hash) (defaults to: {})
  • options (String) (defaults to: {})

    :default_workflow workflow to query for if not using the qualified format

Options Hash (options):

  • :limit (Integer)

    maximum number of druids to return (nil for no limit)

Returns:

  • (Array<String>)

    Array of druids



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/dor/workflow/client/queues.rb', line 56

def objects_for_workstep(completed, waiting, lane_id = 'default', options = {})
  waiting_param = qualify_step(options[:default_workflow], waiting)
  uri_string = "workflow_queue?waiting=#{waiting_param}"
  if completed
    Array(completed).each do |step|
      completed_param = qualify_step(options[:default_workflow], step)
      uri_string += "&completed=#{completed_param}"
    end
  end

  uri_string += "&limit=#{options[:limit].to_i}" if options[:limit]&.to_i&.positive?
  uri_string += "&lane-id=#{lane_id}"

  resp = requestor.request uri_string
  #
  # response looks like:
  #    <objects count="2">
  #      <object id="druid:ab123de4567"/>
  #      <object id="druid:ab123de9012"/>
  #    </objects>
  #
  # convert into:
  #   ['druid:ab123de4567', 'druid:ab123de9012']
  #
  Nokogiri::XML(resp).xpath('//object[@id]').map { |n| n[:id] }
end