Class: CommandTower::Workflows::Messaging::Handoff::ProcessWorkflow

Inherits:
ApplicationWorkflow show all
Defined in:
app/workflows/command_tower/workflows/messaging/handoff/process_workflow.rb

Overview

Job-entry orchestration: advance accepted communications into execution scheduling.

Constant Summary

Constants inherited from ApplicationWorkflow

ApplicationWorkflow::ALLOWED_RETRY_STRATEGIES, ApplicationWorkflow::InvalidTransactionResult, ApplicationWorkflow::TransactionFailure

Instance Method Summary collapse

Methods inherited from ApplicationWorkflow

call, call_from_job, continuation_max_attempts, declared_retry_strategy, mark_impersonation_activity!, retry_strategy, validate_retry_strategy!

Methods included from Impersonation::ActivityDeclaration

included

Methods included from Logging::LifecycleDeclaration

included

Methods included from Execution::ContextAccess

#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event

Methods included from Transactional

#fail_transaction!, #transaction

Instance Method Details

#call(communication_id:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/workflows/command_tower/workflows/messaging/handoff/process_workflow.rb', line 11

def call(communication_id:)
  communication = load_communication(communication_id)
  if communication.nil?
    return success(
      payload: { outcome: :noop, reason: :missing },
      http_status: :ok,
    )
  end

  if communication.handoff_terminal?
    return success(
      payload: { outcome: :noop, reason: :terminal, communication_id: communication.id },
      http_status: :ok,
    )
  end

  CommandTower::Messaging::Handoff::OperationLogger.started(communication:)

  begin
    communication = CommandTower::Messaging::Handoff::AdvanceCommunication.call(
      communication:,
    )
    CommandTower::Messaging::Handoff::OperationLogger.succeeded(communication:)
    schedule_execution!(communication)
    success(
      payload: {
        outcome: :advanced,
        communication_id: communication.id,
        execution_handoff_status: communication.execution_handoff_status,
      },
      http_status: :ok,
    )
  rescue StandardError => error
    mark_failed(communication)
    failed = load_communication(communication_id)
    if failed
      CommandTower::Messaging::Handoff::OperationLogger.failed(
        communication: failed,
        error:,
      )
    end
    failure(
      errors: [CommandTower::Errors::InternalError.new(cause: error)],
      http_status: :internal_server_error,
      meta: { propagate_to_job: true },
    )
  end
end