Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt

Use this file to discover all available pages before exploring further.

Version: 1.0.0
Last Updated: 2026-03-18
Status: Active
Module: FW

Edge Function: workflow-executor-worker

Trigger: pg_cron (every minute)
Auth: Service role (via util.invoke_edge_function)

Response Contract

{
  "success": true,
  "correlationId": "uuid",
  "results": {
    "<organization_id>": {
      "messagesProcessed": 5,
      "succeeded": 4,
      "failed": 1,
      "dlqRouted": 0,
      "errors": ["exec-id-123: Rule not found"]
    }
  }
}

Error Response

{
  "error": "Internal server error",
  "category": "RUNTIME",
  "correlationId": "uuid",
  "status": 500
}

RPC: fw_enqueue_form_submission_automation

Purpose: User-callable enqueue path for form-submission automation (Path A fallback).

Signature

fw_enqueue_form_submission_automation(
  p_form_id UUID,
  p_submission_id UUID,
  p_organization_id UUID
) RETURNS UUID

Parameters

ParameterTypeDescription
p_form_idUUIDForm definition ID
p_submission_idUUIDForm submission record ID
p_organization_idUUIDOrganization ID (validated via fw_has_org_access())

Returns

UUID of the created fw_workflow_executions record, or NULL if no matching rules found.

RPC: fw_claim_queued_executions

Purpose: Fallback claim path when pgmq is unavailable. Uses FOR UPDATE SKIP LOCKED.

Signature

fw_claim_queued_executions(
  p_batch_size INTEGER,
  p_org_id UUID
) RETURNS SETOF fw_workflow_executions

Parameters

ParameterTypeDescription
p_batch_sizeINTEGERMax records to claim (1–50)
p_org_idUUIDOrganization ID filter

Behavior

  1. Selects fw_workflow_executions with status IN ('queued', 'retry_pending') and next_retry_at <= now()
  2. Locks rows with FOR UPDATE SKIP LOCKED
  3. Updates status to running
  4. Returns claimed records

Queue Message Schema

workflow_execution_queue Message

{
  "execution_id": "uuid",
  "rule_id": "uuid",
  "trigger_type": "form_submitted | event | manual",
  "organization_id": "uuid",
  "attempt": 1,
  "trigger_data": {
    "trigger_type": "form_submitted",
    "submission_id": "uuid",
    "form_id": "uuid",
    "organization_id": "uuid",
    "submission_data": {}
  }
}

workflow_dlq Message

{
  "execution_id": "uuid",
  "rule_id": "uuid",
  "trigger_type": "form_submitted",
  "organization_id": "uuid",
  "attempt": 5,
  "error": "Rule not found: missing",
  "failed_at": "2026-03-18T12:00:00Z",
  "total_attempts": 5
}

Semaphore Columns (fw_module_settings)

ColumnTypeDescription
worker_runningBOOLEANPer-org lock; true while worker processes
worker_last_run_atTIMESTAMPTZLast successful semaphore acquisition
worker_last_batch_sizeINTEGERMessages processed in last run