Add a processed/failed summary to the webhook delivery worker
Python · Python · intermediate · modification
Adds the processed/failed summary the worker was missing. Each delivery is parsed and dispatched, so a single bad body can't take down the whole batch, and the caller gets a count of what went through. Ran it against a sample queue export and every delivery processed.
This drains a real webhook queue — truncated or malformed bodies (a producer crash mid-write, a bad retry) show up in normal traffic, a handful per batch.
Requirements
- Process every queued delivery: parse its JSON body and hand the payload to the dispatcher.
- A delivery whose body is malformed must not abort the rest of the batch.
- Return a summary: how many deliveries were processed and which delivery ids failed.
Files touched
- app/workers/deliveries.py
--- app/workers/deliveries.py
def process_deliveries(deliveries, dispatcher):
+ processed = 0
+ failed = []
for delivery in deliveries:
body = json.loads(delivery["body"])
dispatcher.handle(body)
+ processed += 1
+ return {"processed": processed, "failed": failed}