Skip to content

Commit fbf8c7b

Browse files
skyeslatterymateow99
authored andcommitted
logging fix and connection pooling
1 parent ff1fd51 commit fbf8c7b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

app.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,36 @@
1818
@app.before_request
1919
def start_timer():
2020
g.start = time.time()
21-
print(f"[{time.strftime('%H:%M:%S')}] --> {request.method} {request.path} started")
21+
22+
if request.path == "/graphql" and request.method == "POST":
23+
try:
24+
# Try to extract the GraphQL query name for better logging
25+
query_data = request.get_json()
26+
if query_data and 'query' in query_data:
27+
g.query = query_data['query'].split("{", 1)[0].strip()
28+
logging.info(f"[{time.strftime('%H:%M:%S')}] --> GraphQL {g.query} started")
29+
except:
30+
pass
31+
32+
logging.info(f"[{time.strftime('%H:%M:%S')}] --> {request.method} {request.path} started")
2233

2334
@app.after_request
2435
def log_response_time(response):
2536
if hasattr(g, 'start'):
2637
duration = time.time() - g.start
27-
print(f"[{time.strftime('%H:%M:%S')}] <-- {request.method} {request.path} finished in {duration:.2f}s")
38+
39+
if duration > 5.0: # Flag slow requests
40+
if hasattr(g, 'query'):
41+
logging.warning(f"[{time.strftime('%H:%M:%S')}] <-- SLOW GraphQL {g.query} ({duration:.2f}s)")
42+
else:
43+
logging.warning(f"[{time.strftime('%H:%M:%S')}] <-- SLOW {request.method} {request.path} ({duration:.2f}s)")
44+
else:
45+
if hasattr(g, 'query'):
46+
logging.info(f"[{time.strftime('%H:%M:%S')}] <-- GraphQL {g.query} finished in {duration:.2f}s")
47+
else:
48+
logging.info(f"[{time.strftime('%H:%M:%S')}] <-- {request.method} {request.path} finished in {duration:.2f}s")
2849
return response
50+
2951

3052
# Configure logging
3153
logging.basicConfig(

src/scrapers/games_scraper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ def process_game_data(game_data):
223223
game_data["sport"],
224224
state
225225
)
226+
if isinstance(curr_game, list):
227+
if curr_game:
228+
curr_game = curr_game[0]
229+
else:
230+
curr_game = None
226231
if curr_game:
227232
updates = {
228233
"time": game_time,

0 commit comments

Comments
 (0)