Skip to content

Commit dc451d3

Browse files
committed
Refactor get_logs function to retrieve backtest logs directly from data provider instead of reading from file system
1 parent 6a488a9 commit dc451d3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

jesse/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,14 +667,12 @@ def get_logs(session_id: str, token: str = Query(...)):
667667
return authenticator.unauthorized_response()
668668

669669
try:
670-
path = f'storage/logs/backtest-mode/{session_id}.txt'
670+
from jesse.modes.data_provider import get_backtest_logs
671+
content = get_backtest_logs(session_id)
671672

672-
if not os.path.exists(path):
673+
if content is None:
673674
return JSONResponse({'error': 'Log file not found'}, status_code=404)
674675

675-
with open(path, 'r') as f:
676-
content = f.read()
677-
678676
return JSONResponse({'content': content}, status_code=200)
679677
except Exception as e:
680678
return JSONResponse({'error': str(e)}, status_code=500)

jesse/modes/data_provider.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
import numpy as np
34
import peewee
45
from fastapi.responses import FileResponse
@@ -165,3 +166,15 @@ def download_file(mode: str, file_type: str, session_id: str = None):
165166
raise Exception(f'Unknown file type: {file_type} or mode: {mode}')
166167

167168
return FileResponse(path=path, filename=filename, media_type='application/octet-stream')
169+
170+
171+
def get_backtest_logs(session_id: str):
172+
path = f"storage/logs/backtest-mode/{session_id}.txt"
173+
174+
if not os.path.exists(path):
175+
return None
176+
177+
with open(path, "r") as f:
178+
content = f.read()
179+
180+
return content

0 commit comments

Comments
 (0)