Skip to content

Commit

Permalink
Merge branch 'main' into extend_default_min_transfers_to_all_networks
Browse files Browse the repository at this point in the history
  • Loading branch information
harisang authored Jan 7, 2025
2 parents df32bc5 + 2bbd634 commit 0dce228
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion queries/orderbook/order_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ price_data as (
on tdp.auction_id = ap_protocol.auction_id and tdp.surplus_token = ap_protocol.token
),

trade_data_processed_with_prices as (
trade_data_processed_with_prices as materialized (
select --noqa: ST06
tdp.auction_id,
tdp.solver,
Expand Down
6 changes: 6 additions & 0 deletions src/data_sync/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def compute_block_and_month_range( # pylint: disable=too-many-locals
current_month = (
f"{current_month_end_datetime.year}_{current_month_end_datetime.month}"
)
## in case the month is 1-9, we add a "0" prefix, so that we have a fixed-length representation
## e.g., 2024-12, 2024-01
if len(current_month) < 7:
current_month = current_month[:5] + "0" + current_month[5]
months_list = [current_month]
block_range = [(current_month_start_block, current_month_end_block)]
if current_month_end_datetime.day == 1 or recompute_previous_month:
Expand All @@ -90,6 +94,8 @@ def compute_block_and_month_range( # pylint: disable=too-many-locals
previous_month = f"""{current_month_end_datetime.year}_
{current_month_end_datetime.month - 1}
"""
if len(previous_month) < 7:
previous_month = previous_month[:5] + "0" + previous_month[5]
previous_month_start_datetime = datetime(
current_month_end_datetime.year,
current_month_end_datetime.month - 1,
Expand Down
13 changes: 11 additions & 2 deletions src/fetch/orderbook.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=duplicate-code
"""Basic client for connecting to postgres database with login credentials"""

from __future__ import annotations
Expand Down Expand Up @@ -51,8 +52,16 @@ def pg_engine(db_env: OrderbookEnv) -> Engine:
else:
db_url = os.environ[f"{db_env}_DB_URL"]

db_string = f"postgresql+psycopg2://{db_url}"
return create_engine(db_string)
return create_engine(
f"postgresql+psycopg2://{db_url}",
pool_pre_ping=True,
connect_args={
"keepalives": 1,
"keepalives_idle": 30,
"keepalives_interval": 10,
"keepalives_count": 5,
},
)

@classmethod
def _read_query_for_env(
Expand Down

0 comments on commit 0dce228

Please sign in to comment.