Skip to content

Commit

Permalink
add logging to tao_price shovel
Browse files Browse the repository at this point in the history
  • Loading branch information
hey-michal committed Dec 12, 2024
1 parent 263c237 commit 976917c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scraper_service/shovel_tao_price/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,38 @@ class TaoPriceShovel(ShovelBaseClass):
starting_block=2137

def process_block(self, n):
logging.info("0. processing block...")
# `skip_interval` has a hiccup sometimes
# for unknown reasons and its not elastic
# enough to handle conditions
if n > THRESHOLD_BLOCK:
logging.info("1")
if n % BLOCKS_IN_36_S != 0:
logging.info("2")
return
else:
logging.info("3")
if n % BLOCKS_A_DAY != 0:
logging.info("4")
return
logging.info("5. processing.")
do_process_block(n, self.table_name)

@retry(
wait=wait_fixed(30),
)
def do_process_block(n, table_name):
logging.info(f"starting block {n}")
substrate = get_substrate_client()

logging.info("got substrate client")
if not table_exists(table_name):
logging.info("no table....")
first_run(table_name)

logging.info("got table")
block_hash = substrate.get_block_hash(n)
logging.info(f"getting block hash {block_hash}")
block_timestamp = int(
substrate.query(
"Timestamp",
Expand All @@ -55,18 +66,25 @@ def do_process_block(n, table_name):
/ 1000
)

logging.info(f"block timestamp {block_timestamp}")

if block_timestamp == 0:
logging.info(f"timestamp is 0")
return

logging.info("getting price")
latest_price_data = get_price_by_time(block_timestamp)
logging.info("got price data")

if latest_price_data:
logging.info("and it is here")
buffer_insert(table_name, [block_timestamp, *latest_price_data])
else:
raise Exception("Rate limit error encountered. Waiting before retrying...")




def first_run(table_name):
query = f"""
CREATE TABLE IF NOT EXISTS {table_name} (
Expand Down

0 comments on commit 976917c

Please sign in to comment.