Skip to content

Commit

Permalink
Object deletions
Browse files Browse the repository at this point in the history
  • Loading branch information
gheise committed Mar 22, 2022
1 parent baf370c commit a9f57bc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mev_inspect/s3_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import logging
import os
from datetime import datetime
from typing import Iterator, Optional, Tuple, TypeVar

import boto3
Expand Down Expand Up @@ -36,7 +35,6 @@ def _export_block_by_table(inspect_db_session, block_number: int, table: str) ->
client = get_s3_client()
export_bucket_name = get_export_bucket_name()
export_statement = _get_export_statement(table)
date = round(datetime.utcnow().timestamp())

object_key = f"{table}/flashbots_{block_number}.json"

Expand All @@ -52,12 +50,21 @@ def _export_block_by_table(inspect_db_session, block_number: int, table: str) ->
existing_object_size = _get_object_size(client, export_bucket_name, object_key)
if existing_object_size is None or existing_object_size == 0:
logger.info(f"Skipping {table} for block {block_number} - no data")
client.delete_object(
Bucket=export_bucket_name,
Key=object_key,
)
return

mev_summary_json_fileobj = BytesIteratorIO(
(f"{json.dumps(row)}\n".encode("utf-8") for (row,) in mev_summary_json_results)
)

client.delete_object(
Bucket=export_bucket_name,
Key=object_key,
)

client.upload_fileobj(
mev_summary_json_fileobj,
Bucket=export_bucket_name,
Expand Down

0 comments on commit a9f57bc

Please sign in to comment.