{
        "description": "Process TaxCore retry queue every 5 minutes (handled by PHP cron job)",
        "schedule": "*/5 * * * *",
        "priority": 5,
        "steps": [
            {
                "step": 1,
                "action": "query",
                "name": "get_queue_items",
                "query": "SELECT q.*, s.* FROM taxcore_queue q JOIN taxcore_submissions s ON q.submission_id = s.submission_id WHERE q.status = 'queued' AND q.retry_count < q.max_retries AND q.next_retry_at <= NOW() ORDER BY q.priority DESC, q.next_retry_at ASC LIMIT 50",
                "required": false
            },
            {
                "step": 2,
                "action": "foreach",
                "name": "process_each_item",
                "array": "${step1.result}",
                "steps": [
                    {
                        "step": 1,
                        "action": "http_post",
                        "name": "retry_submission",
                        "url": "http://taxcore-service:3001/submit",
                        "headers": {"Content-Type": "application/json"},
                        "body": "${item.request_payload}",
                        "handle_error": "continue"
                    },
                    {
                        "step": 2,
                        "action": "conditional",
                        "name": "update_based_on_result",
                        "condition": "step1.status == 200",
                        "if_true": {
                            "action": "update",
                            "query": "DELETE FROM taxcore_queue WHERE queue_id = ${item.queue_id}; UPDATE taxcore_submissions SET status = 'success', taxcore_invoice_number = ${step1.response.invoiceNumber} WHERE submission_id = ${item.submission_id}"
                        },
                        "if_false": {
                            "action": "update",
                            "query": "UPDATE taxcore_queue SET retry_count = retry_count + 1, next_retry_at = NOW() + INTERVAL '${item.base_delay_minutes * POWER(item.backoff_multiplier, item.retry_count + 1)} minutes', last_error = ${step1.error} WHERE queue_id = ${item.queue_id}"
                        }
                    }
                ]
            },
            {
                "step": 3,
                "action": "notify",
                "name": "log_completion",
                "channel": "log",
                "message": "Processed ${step1.result.length} queue items"
            }
        ]
    }