From d76cbaf33bd127f4d22b3305cc3a4fa99f4b25a7 Mon Sep 17 00:00:00 2001 From: patrick borowy Date: Tue, 2 Apr 2024 09:52:44 +0200 Subject: [PATCH] improve commit batch, handles and log batch which items were already updated --- src/commit_analyzed_batch.py | 5 +++-- src/transactioneer.py | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/commit_analyzed_batch.py b/src/commit_analyzed_batch.py index ded0d71..1593c29 100644 --- a/src/commit_analyzed_batch.py +++ b/src/commit_analyzed_batch.py @@ -27,13 +27,14 @@ async def commit_analyzed_batch(processed_batch, app): app["web3_configuration"]["contracts"], app["web3_configuration"]["read_web3"], app["web3_configuration"]["write_web3"], - app["web3_configuration"], + app["web3_configuration"] ) receipt = await get_transaction_receipt( transaction_hash, previous_nonce, app["web3_configuration"] ) logging.info("COMMIT OK") - return transaction_hash, cid + return (transaction_hash, cid) + return (None, None) except Exception as e: logging.exception("An error occured while commiting a batch") raise e diff --git a/src/transactioneer.py b/src/transactioneer.py index 457ad62..53c535c 100644 --- a/src/transactioneer.py +++ b/src/transactioneer.py @@ -154,19 +154,22 @@ async def create_task(items, app): logging.info("===") with tracer.start_as_current_span("commit_analyzed_batch") as commit_analyzed_batch_span: try: - transaction_hash, cid = await commit_analyzed_batch( + (transaction_hash, cid) = await commit_analyzed_batch( {"items": items, "kind": "SPOTTING"}, app ) - commit_analyzed_batch_span.set_status(StatusCode.OK) - commit_analyzed_batch_span.set_attribute("CID", cid) - commit_analyzed_batch_span.set_attribute( - "TX", transaction_hash.hex() - ) - receipt_count.inc({}) - receipt_count_populated.inc( - { "CID": cid, "TX": transaction_hash.hex() } - ) - logging.info("COMMIT OK") + if cid and transaction_hash: + commit_analyzed_batch_span.set_status(StatusCode.OK) + commit_analyzed_batch_span.set_attribute("CID", cid) + commit_analyzed_batch_span.set_attribute( + "TX", transaction_hash.hex() + ) + receipt_count.inc({}) + receipt_count_populated.inc( + { "CID": cid, "TX": transaction_hash.hex() } + ) + logging.info("COMMIT OK") + else: + logging.info("Every item of this batch are already collected") except Exception as e: logging.info("COMMIT FAILED") logging.exception("An Error occured commiting analyzed batch") @@ -231,7 +234,7 @@ async def do_claim_master(app): def start_transactioneer(): - if os.getenv('TRACE'): + if os.getenv("TRACE", False): setup_tracing() logging.basicConfig( level=logging.DEBUG,