module Temporal::Metadata

Constants

ACTIVITY_TYPE
WORKFLOW_TASK_TYPE
WORKFLOW_TYPE

Public Class Methods

generate(type, data, namespace = nil) click to toggle source
# File lib/temporal/metadata.rb, line 16
def generate(type, data, namespace = nil)
  case type
  when ACTIVITY_TYPE
    activity_metadata_from(data, namespace)
  when WORKFLOW_TASK_TYPE
    workflow_task_metadata_from(data, namespace)
  when WORKFLOW_TYPE
    workflow_metadata_from(data)
  else
    raise InternalError, 'Unsupported metadata type'
  end
end

Private Class Methods

activity_metadata_from(task, namespace) click to toggle source
# File lib/temporal/metadata.rb, line 39
def activity_metadata_from(task, namespace)
  Metadata::Activity.new(
    namespace: namespace,
    id: task.activity_id,
    name: task.activity_type.name,
    task_token: task.task_token,
    attempt: task.attempt,
    workflow_run_id: task.workflow_execution.run_id,
    workflow_id: task.workflow_execution.workflow_id,
    workflow_name: task.workflow_type.name,
    headers: headers(task.header&.fields),
    heartbeat_details: from_details_payloads(task.heartbeat_details)
  )
end
headers(fields) click to toggle source
# File lib/temporal/metadata.rb, line 31
def headers(fields)
  result = {}
  fields.each do |field, payload|
    result[field] = from_payload(payload)
  end
  result
end
workflow_metadata_from(event) click to toggle source
# File lib/temporal/metadata.rb, line 66
def workflow_metadata_from(event)
  Metadata::Workflow.new(
    name: event.workflow_type.name,
    run_id: event.original_execution_run_id,
    attempt: event.attempt,
    headers: headers(event.header&.fields)
  )
end
workflow_task_metadata_from(task, namespace) click to toggle source
# File lib/temporal/metadata.rb, line 54
def workflow_task_metadata_from(task, namespace)
  Metadata::WorkflowTask.new(
    namespace: namespace,
    id: task.started_event_id,
    task_token: task.task_token,
    attempt: task.attempt,
    workflow_run_id: task.workflow_execution.run_id,
    workflow_id: task.workflow_execution.workflow_id,
    workflow_name: task.workflow_type.name
  )
end