{
        "schedule": "*/5 * * * *",
        "priority": 5,
        "max_retries": 1,
        "steps": [
            {
                "step": 1,
                "action": "query",
                "description": "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",
                "description": "Process each retry item",
                "items": "${step1.results}",
                "steps": [
                    {
                        "step": "2a",
                        "action": "http_post",
                        "url": "http://taxcore-service:3001/${item.reference_table === 'invoices' ? 'invoice' : 'sale'}",
                        "payload": "${item.payload}"
                    },
                    {
                        "step": "2b",
                        "action": "conditional",
                        "condition": "${step2a.success}",
                        "then": {
                            "action": "update",
                            "table": "taxcore_queue",
                            "where": "queue_id = ${item.queue_id}",
                            "set": {"status": "completed"}
                        },
                        "else": {
                            "action": "update",
                            "table": "taxcore_queue",
                            "where": "queue_id = ${item.queue_id}",
                            "set": {
                                "retry_count": "${item.retry_count + 1}",
                                "last_error": "${step2a.error}"
                            }
                        }
                    }
                ]
            }
        ]
    }