2 points · by Sreejay_reddy · 5mo ago · 0 comments
from sentinel import Sentinel import psycopg
sentinel = Sentinel(get_conn=get_conn)
def process_payment_webhook(charge_id: str, amount: int): result = sentinel.once( key=f"stripe-webhook:{charge_id}", fn=charge_customer, kwargs={"charge_id": charge_id, "amount": amount}, ttl_ms=5000, hard_ttl_ms=30000 )
if result.execution_alive:
# Another worker is actively processing this charge
return {"status": "processing"}
elif result.uncertain:
# Execution failed midway, side effects may have partially applied
# Use reconciliation tooling to inspect and resolve
return {"status": "uncertain", "reconcile": result.reconcile}
else:
# Newly completed or replayed from cache
# Safe to return regardless of how many times this webhook fired
return {"status": "ok", "response": result.response}
AsyncSentinel is available for async contexts.Temporal and Airflow assume your tasks are idempotent. Sentinel is what makes them actually idempotent.
"GitHub: github.com/Sreejay-Reddy/Sentinel | pip install sentinel-coordination"
No comments yet.