Skip to content

Commit

Permalink
Retry created receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
Atralupus committed Jan 21, 2025
1 parent c9db6ca commit c2215d9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions worker/worker/tracker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import os
import boto3
from collections import defaultdict
from typing import Optional, Tuple

from datetime import datetime, timezone, timedelta
from gql.dsl import dsl_gql, DSLQuery
from sqlalchemy import create_engine, select
from sqlalchemy.orm import sessionmaker, scoped_session
Expand All @@ -24,6 +26,9 @@
True
)["Value"]

SQS_URL = os.environ.get("SQS_URL")
sqs = boto3.client("sqs", region_name=os.environ.get("REGION_NAME"))

LIMIT = 200

engine = create_engine(DB_URI, pool_size=5, max_overflow=5)
Expand Down Expand Up @@ -69,6 +74,24 @@ def track_tx(event, context):
).order_by(Receipt.id).limit(LIMIT)
).fetchall()

now = datetime.now(tz=timezone.utc)
created_receipt_list = sess.scalars(
select(Receipt).where(
Receipt.created_at <= now - timedelta(minutes=5),
Receipt.status == ReceiptStatus.VALID,
Receipt.tx_status == TxStatus.CREATED
).order_by(Receipt.id).limit(LIMIT)
).fetchall()

if created_receipt_list:
for created_receipt in created_receipt_list:
msg = {
"uuid": str(created_receipt.uuid),
}

sqs.send_message(QueueUrl=SQS_URL, MessageBody=json.dumps(msg))
logger.info(f"Found created receipt [{len(created_receipt_list)}], re queuing.")

result = defaultdict(list)
for receipt in receipt_list:
tx_id, tx_status, msg = process(GQL_DICT[receipt.planet_id], receipt.tx_id)
Expand Down

0 comments on commit c2215d9

Please sign in to comment.