{
  "name": "REVOPS-LI-005 | 06 | Duplicate cleanup operations",
  "nodes": [
    {
      "parameters": {},
      "id": "a325de24-52cc-4e46-99de-1aab27916928",
      "name": "Duplicate Workflow Error",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const e=$input.first().json;return [{json:{execution_id:String(e.execution?.id||''),workflow:String(e.workflow?.name||''),node:String(e.execution?.lastNodeExecuted||''),message:String(e.execution?.error?.message||'failed').replace(/Bearer\\s+\\S+/gi,'Bearer [REDACTED]').slice(0,1000)}}];"
      },
      "id": "72ca8a6c-5049-48f5-836f-ebc38b7b61a1",
      "name": "Redact Failure",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        270,
        0
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT duplicate_cleanup.fail_execution($1::text,$2::jsonb);",
        "options": {
          "queryReplacement": "={{ [$json.execution_id,JSON.stringify($json)] }}"
        }
      },
      "id": "bf425bfa-05ab-4198-a9c7-d71287995872",
      "name": "Record Failure and Release Lease",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        540,
        0
      ],
      "credentials": {
        "postgres": {
          "id": "REPLACE_POSTGRES_CREDENTIAL",
          "name": "ATTRIBUTION Postgres"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "id": "d8282c19-0b86-40f0-ab21-f65a0735a22c",
      "name": "Inspect Queue Health",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        810,
        0
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT status,count(*) AS records,min(updated_at) AS oldest FROM duplicate_cleanup.candidates GROUP BY status UNION ALL SELECT 'EVENT_'||status,count(*),min(updated_at) FROM duplicate_cleanup.events GROUP BY status;",
        "options": {
          "queryReplacement": "={{ [] }}"
        }
      },
      "id": "2f7f318a-e5c6-4da8-94d2-1dd6ff088cb8",
      "name": "Return Operational Counts",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1080,
        0
      ],
      "credentials": {
        "postgres": {
          "id": "REPLACE_POSTGRES_CREDENTIAL",
          "name": "ATTRIBUTION Postgres"
        }
      }
    },
    {
      "parameters": {
        "content": "## Error and backlog visibility\nSelect this workflow as the Error Workflow for workflows 01, 02 and 04.\nFailures are stored without credentials. A merge attempt is never automatically retried; stale MERGING candidates enter reconciliation.",
        "width": 700,
        "height": 220
      },
      "id": "3b23b7b3-c009-42b5-b363-f315d86fc018",
      "name": "Workflow Guide",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -270
      ]
    }
  ],
  "connections": {
    "Duplicate Workflow Error": {
      "main": [
        [
          {
            "node": "Redact Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redact Failure": {
      "main": [
        [
          {
            "node": "Record Failure and Release Lease",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inspect Queue Health": {
      "main": [
        [
          {
            "node": "Return Operational Counts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Tbilisi",
    "saveExecutionProgress": true
  },
  "active": false,
  "pinData": {},
  "tags": []
}
