Skip to content

Commit 6547614

Browse files
authored
Merge pull request #213 from UW-Macrostrat/fix-usage-stats
Add debugging to usage stats
2 parents 7d75c97 + 3335cdc commit 6547614

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

services/usage-stats/worker.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import asyncio
22
import os
33
import signal
4-
import time
4+
import traceback
5+
from dotenv import load_dotenv
56

67
from dotenv import load_dotenv
78
from src.macrostrat import get_macrostrat_data
@@ -19,7 +20,7 @@ def get_env_var(name: str, timeout: int = 30) -> str:
1920
for _ in range(timeout):
2021
value = os.getenv(name)
2122
if value:
22-
print(f"[DEBUG] {name} found: {value}")
23+
print(f"[DEBUG] {name} found")
2324
return value
2425
print(f"[DEBUG] Waiting for environment variable {name}...")
2526
time.sleep(1)
@@ -30,21 +31,21 @@ def get_env_var(name: str, timeout: int = 30) -> str:
3031

3132
async def periodic_task(stop_event: asyncio.Event, db_url: str, mariadb_url: str):
3233
while not stop_event.is_set():
34+
print("[DEBUG] Starting periodic data fetch")
3335
try:
34-
# Pass MARIADB_URL if get_rockd_data needs it
3536
await get_rockd_data(mariadb_url, db_url)
36-
37-
# Pass DATABASE_URL if get_macrostrat_data needs it
37+
print("[DEBUG] Finished get_rockd_data")
3838
await get_macrostrat_data(mariadb_url, db_url)
39-
except Exception as e:
40-
print(f"Error in periodic_task: {e}")
39+
print("[DEBUG] Finished get_macrostrat_data")
40+
except Exception:
41+
print("Error in periodic_task:", flush=True)
42+
traceback.print_exc()
4143

4244
try:
43-
await asyncio.wait_for(stop_event.wait(), timeout=10)
45+
await asyncio.wait_for(stop_event.wait(), timeout=30)
4446
except asyncio.TimeoutError:
4547
pass
4648

47-
4849
async def main():
4950
stop_event = asyncio.Event()
5051
# Fetch environment variables once at startup

0 commit comments

Comments
 (0)