Class: Dor::Services::Client::Process

Inherits:
VersionedService show all
Defined in:
lib/dor/services/client/process.rb

Overview

API calls around workflow process for an object.

Constant Summary

Constants inherited from VersionedService

VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from VersionedService

#async_result

Constructor Details

#initialize(connection:, version:, object_identifier:, workflow_name:, process:, object_workflow_client:) ⇒ Process

Returns a new instance of Process.

Parameters:

  • object_identifier (String)

    the druid for the object

  • workflow_name (String)

    The name of the workflow

  • process (String)

    The name of the workflow step



11
12
13
14
15
16
17
# File 'lib/dor/services/client/process.rb', line 11

def initialize(connection:, version:, object_identifier:, workflow_name:, process:, object_workflow_client:) # rubocop:disable Metrics/ParameterLists
  super(connection: connection, version: version)
  @object_identifier = object_identifier
  @workflow_name = workflow_name
  @process = process
  @object_workflow_client = object_workflow_client
end

Instance Attribute Details

#object_identifierObject (readonly)

Returns the value of attribute object_identifier.



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

def object_identifier
  @object_identifier
end

#object_workflow_clientObject (readonly)

Returns the value of attribute object_workflow_client.



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

def object_workflow_client
  @object_workflow_client
end

#processObject (readonly)

Returns the value of attribute process.



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

def process
  @process
end

#workflow_nameObject (readonly)

Returns the value of attribute workflow_name.



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

def workflow_name
  @workflow_name
end

Instance Method Details

#statusString?

Retrieves the process status of the given workflow for the given object identifier

Returns:

  • (String, nil)

    status



21
22
23
24
25
26
27
# File 'lib/dor/services/client/process.rb', line 21

def status
  doc = object_workflow_client.find.ng_xml

  processes = doc.root.xpath("//process[@name='#{process}']")
  process = processes.max { |a, b| a.attr('version').to_i <=> b.attr('version').to_i }
  process&.attr('status')
end

#update(status:, elapsed: 0, lifecycle: nil, note: nil, current_status: nil) ⇒ Object

Updates the status of one step in a workflow.

Parameters:

  • status (String)

    The status of the process.

  • elapsed (Float) (defaults to: 0)

    The number of seconds it took to complete this step. Can have a decimal. Is set to 0 if not passed in.

  • lifecycle (String) (defaults to: nil)

    Bookeeping label for this particular workflow step. Examples are: ‘registered’, ‘shelved’

  • note (String) (defaults to: nil)

    Any kind of string annotation that you want to attach to the workflow

  • current_status (String) (defaults to: nil)

    Setting this string tells the workflow service to compare the current status to this value.

Raises:



36
37
38
# File 'lib/dor/services/client/process.rb', line 36

def update(status:, elapsed: 0, lifecycle: nil, note: nil, current_status: nil)
  perform_update(status: status, elapsed: elapsed, lifecycle: lifecycle, note: note, current_status: current_status)
end

#update_error(error_msg:, error_text: nil) ⇒ Object

Updates the status of one step in a workflow to error.

Parameters:

  • error_msg (String)

    The error message. Ideally, this is a brief message describing the error

  • error_text (String) (defaults to: nil)

    A slot to hold more information about the error, like a full stacktrace



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

def update_error(error_msg:, error_text: nil)
  perform_update(status: 'error', error_msg: error_msg, error_text: error_text)
end