Skip to content

Commit 773d498

Browse files
committed
Fix invalid webhook handling
1 parent 5033741 commit 773d498

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/examples/cvat/recording-oracle/src/crons/_utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ def wrapper():
6969

7070

7171
@contextmanager
72-
def handle_webhook(logger: logging.Logger, session: Session, webhook: Webhook):
72+
def handle_webhook(
73+
logger: logging.Logger,
74+
session: Session,
75+
webhook: Webhook,
76+
*,
77+
queue: webhook_service.OracleWebhookQueue,
78+
):
7379
savepoint = session.begin_nested()
7480
logger.debug(
7581
"Processing webhook "
@@ -83,9 +89,9 @@ def handle_webhook(logger: logging.Logger, session: Session, webhook: Webhook):
8389
# TODO: should we rollback on any errors or just on database errors?
8490
savepoint.rollback()
8591
logger.exception(f"Webhook {webhook.id} sending failed: {e}")
86-
webhook_service.outbox.handle_webhook_fail(session, webhook.id)
92+
queue.handle_webhook_fail(session, webhook.id)
8793
else:
88-
webhook_service.outbox.handle_webhook_success(session, webhook.id)
94+
queue.handle_webhook_success(session, webhook.id)
8995
logger.debug("Webhook handled successfully")
9096

9197

@@ -124,6 +130,6 @@ def process_outgoing_webhooks(
124130
for_update=ForUpdateParams(skip_locked=True),
125131
)
126132
for webhook in webhooks:
127-
with handle_webhook(logger, session, webhook):
133+
with handle_webhook(logger, session, webhook, queue=oracle_db_service.outbox):
128134
webhook_url = url_getter(webhook.chain_id, webhook.escrow_address)
129135
send_webhook(webhook_url, webhook, with_timestamp=with_timestamp)

packages/examples/cvat/recording-oracle/src/crons/process_exchange_oracle_webhooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def process_incoming_exchange_oracle_webhooks(logger: logging.Logger, session: S
2626
)
2727

2828
for webhook in webhooks:
29-
with handle_webhook(logger, session, webhook):
29+
with handle_webhook(logger, session, webhook, queue=oracle_db_service.inbox):
3030
handle_exchange_oracle_event(webhook, db_session=session)
3131

3232

0 commit comments

Comments
 (0)