{
        "description": "Process pending TaxCore retry queue items every 5 minutes",
        "schedule": "*/5 * * * *",
        "priority": 5,
        "steps": [
            {
                "step": 1,
                "action": "query",
                "name": "get_pending_retries",
                "query": "SELECT * FROM taxcore_queue WHERE status = 'queued' AND retry_count < max_retries AND next_retry_at <= NOW() ORDER BY priority DESC, next_retry_at ASC LIMIT 50"
            },
            {
                "step": 2,
                "action": "foreach",
                "name": "process_each_item",
                "collection": "${step1}",
                "steps": [
                    {
                        "step": "2.1",
                        "action": "http_post",
                        "name": "resubmit",
                        "url": "http://taxcore-service:3001/${item.submission_type}",
                        "body": "${item.payload}",
                        "timeout": 30
                    },
                    {
                        "step": "2.2",
                        "action": "update",
                        "name": "update_retry_count",
                        "table": "taxcore_queue",
                        "where": {"queue_id": "${item.queue_id}"},
                        "data": {
                            "retry_count": "${item.retry_count + 1}",
                            "last_attempt_at": "NOW()",
                            "next_retry_at": "NOW() + INTERVAL '${item.base_delay_minutes * POW(item.backoff_multiplier, item.retry_count + 1)} minutes'"
                        }
                    },
                    {
                        "step": "2.3",
                        "action": "conditional",
                        "name": "check_max_retries",
                        "condition": "${item.retry_count + 1 >= item.max_retries}",
                        "then": {
                            "action": "trigger_event",
                            "event": "taxcore:retry:exceeded",
                            "data": "${item}"
                        }
                    }
                ]
            },
            {
                "step": 3,
                "action": "insert",
                "name": "log_execution",
                "table": "workflow_execution_logs",
                "data": {
                    "workflow_name": "Process TaxCore Retry Queue",
                    "items_processed": "${step1.length}",
                    "execution_time": "${execution_time}"
                }
            }
        ]
    }