diff --git a/worker/worker/handler.py b/worker/worker/handler.py index 9eb5cd8c..a85cc434 100644 --- a/worker/worker/handler.py +++ b/worker/worker/handler.py @@ -8,8 +8,7 @@ from dataclasses import dataclass from typing import List, Optional, Tuple, Union -import requests -from sqlalchemy import create_engine, select +from sqlalchemy import create_engine, select, desc from sqlalchemy.orm import Session, joinedload, scoped_session, sessionmaker from common import logger @@ -142,7 +141,11 @@ def handle(event, context): sess = scoped_session(sessionmaker(bind=engine)) uuid_list = [x.body.get("uuid") for x in message.Records if x.body.get("uuid") is not None] receipt_dict = {str(x.uuid): x for x in sess.scalars(select(Receipt).where(Receipt.uuid.in_(uuid_list)))} - nonce = None + nonce = sess.scalar(select(Receipt.nonce).order_by(desc(Receipt.nonce))) + if nonce: + # Use next nonce + nonce += 1 + for i, record in enumerate(message.Records): # Always 1 record in message since IAP sends one record at a time. # TODO: Handle exceptions and send messages to DLQ