Webhooks¶
SnerdMQ can dispatch tasks via HTTP POST requests to any URL, enabling serverless execution patterns. Instead of running handlers locally, SnerdMQ sends the task payload to your endpoint — perfect for distributed architectures, serverless functions, and cross-service orchestration.
How It Works¶
When you set a webhook_url on a task:
- SnerdMQ skips local handlers entirely
- Sends an HTTP POST to your URL with the task payload as the JSON body
- Includes the
X-SnerdMQ-Event: Executeheader - If your endpoint returns a non-200 status, the task is retried
- If the task permanently fails (max retries reached), SnerdMQ fires a final POST with
X-SnerdMQ-Event: MaxRetriesReached
Webhook Request Format¶
Headers:
Body: The task's data payload as JSON.
DLQ notification (max retries reached):
Code Examples¶
Handling Webhook Requests (Server Side)¶
Here's how to receive SnerdMQ webhook dispatches in your server:
app.post('/webhook/transcode', (req, res) => {
const event = req.headers['x-snerdmq-event'];
if (event === 'Execute') {
// Normal task execution
const { file, format } = req.body;
transcodeVideo(file, format);
res.status(200).json({ status: 'ok' });
} else if (event === 'MaxRetriesReached') {
// DLQ notification — task permanently failed
console.error('Task permanently failed:', req.body);
res.status(200).json({ status: 'acknowledged' });
}
});
@app.post("/webhook/transcode")
async def handle_webhook(request: Request):
event = request.headers.get("X-SnerdMQ-Event")
body = await request.json()
if event == "Execute":
transcode_video(body["file"], body["format"])
return {"status": "ok"}
elif event == "MaxRetriesReached":
logger.error(f"Task permanently failed: {body}")
return {"status": "acknowledged"}
Use Cases¶
- Serverless workers — Dispatch tasks to AWS Lambda, Cloudflare Workers, or Vercel Functions
- Cross-service orchestration — Trigger work in a different microservice
- CI/CD pipelines — Fire webhooks to Jenkins, GitHub Actions, or CircleCI
- Notification systems — Push events to Slack, PagerDuty, or custom alerting
- External APIs — Trigger third-party workflows without local handler code
Webhook + DLQ¶
When a webhook task permanently fails (reaches max_retries), SnerdMQ automatically sends a final HTTP POST to the same webhook_url with the X-SnerdMQ-Event: MaxRetriesReached header. This means you don't need SDK-side max retry handlers for webhook tasks — your endpoint handles both execution and failure notification.