Skip to content

Commit

Permalink
Merge branch 'feature/track-tx-by-planet' into internal
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis committed Aug 27, 2024
2 parents e68fe15 + 0b8e639 commit 7739904
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions worker/worker/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@

from common import logger
from common._graphql import GQL
from common.consts import GQL_DICT
from common.enums import TxStatus
from common.models.receipt import Receipt
from common.utils.aws import fetch_secrets, fetch_parameter
from common.utils.receipt import PlanetID

STAGE = os.environ.get("STAGE")
DB_URI = os.environ.get("DB_URI")
db_password = fetch_secrets(os.environ.get("REGION_NAME"), os.environ.get("SECRET_ARN"))["password"]
DB_URI = DB_URI.replace("[DB_PASSWORD]", db_password)
CURRENT_PLANET = PlanetID.ODIN if os.environ.get("STAGE") == "mainnet" else PlanetID.ODIN_INTERNAL
GQL_URL = f"{os.environ.get('HEADLESS')}/graphql"
HEADLESS_GQL_JWT_SECRET = fetch_parameter(
os.environ.get("REGION_NAME"),
f"{os.environ.get('STAGE')}_9c_IAP_HEADLESS_GQL_JWT_SECRET",
True
)["Value"]

BLOCK_LIMIT = 50
LIMIT = 200

engine = create_engine(DB_URI, pool_size=5, max_overflow=5)


def process(tx_id: str) -> Tuple[str, Optional[TxStatus], Optional[str]]:
client = GQL(GQL_URL, HEADLESS_GQL_JWT_SECRET)
def process(url: str, tx_id: str) -> Tuple[str, Optional[TxStatus], Optional[str]]:
client = GQL(url, HEADLESS_GQL_JWT_SECRET)
query = dsl_gql(
DSLQuery(
client.ds.StandaloneQuery.transaction.select(
Expand Down Expand Up @@ -66,17 +65,17 @@ def track_tx(event, context):
receipt_list = sess.scalars(
select(Receipt).where(
Receipt.tx_status.in_((TxStatus.STAGED, TxStatus.INVALID))
).order_by(Receipt.id).limit(BLOCK_LIMIT)
).order_by(Receipt.id).limit(LIMIT)
).fetchall()

result = defaultdict(list)
for receipt in receipt_list:
tx_id, tx_status, msg = process(receipt.tx_id)
tx_id, tx_status, msg = process(GQL_DICT[receipt.planet_id], receipt.tx_id)
result[tx_status.name].append(tx_id)
receipt.tx_status = tx_status
if msg:
receipt.msg = "\n".join([receipt.msg or "", msg])
sess.add(receipt)
# update_iap_garage(sess, planet_dict[PlanetID.ODIN if os.environ.get("STAGE") == "mainnet" else PlanetID.ODIN_INTERNAL])
sess.commit()

logger.info(f"{len(receipt_list)} transactions are found to track status")
Expand Down
2 changes: 1 addition & 1 deletion worker/worker_cdk_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
layers=[layer],
role=role,
vpc=shared_stack.vpc,
memory_size=256,
memory_size=1024 if config.stage == "mainnet" else 256,
timeout=cdk_core.Duration.seconds(50),
environment=env,
)
Expand Down

0 comments on commit 7739904

Please sign in to comment.