Skip to content

Commit 704b516

Browse files
committed
include report in API response
1 parent 5caf5c1 commit 704b516

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/discord-cluster-manager/api/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,12 @@ async def _stream_submission_response(
253253
default=json_serializer)}\n\n"
254254
return
255255

256-
result = await task
257-
result_data = {"status": "success", "results": [asdict(r) for r in result]}
256+
result, reports = await task
257+
result_data = {
258+
"status": "success",
259+
"results": [asdict(r) for r in result],
260+
"reports": reports,
261+
}
258262
yield f"event: result\ndata: {json.dumps(result_data, default=json_serializer)}\n\n"
259263

260264
except HTTPException as http_exc:

src/discord-cluster-manager/api/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
from datetime import datetime
3+
from typing import List
34

45
import requests
56
from consts import SubmissionMode, get_gpu_by_name
@@ -179,14 +180,21 @@ async def _run_submission(
179180

180181
gpu = selected_gpus[0]
181182

183+
reporters: List[RunProgressReporterAPI] = []
184+
185+
def add_reporter(title: str):
186+
rep = RunProgressReporterAPI(title)
187+
reporters.append(rep)
188+
return rep
189+
182190
try:
183191
tasks = [
184192
command(
185193
sub_id,
186194
submission.code,
187195
submission.file_name,
188196
gpu,
189-
RunProgressReporterAPI(f"{gpu.name} on {gpu.runner}"),
197+
add_reporter(f"{gpu.name} on {gpu.runner}"),
190198
req.task,
191199
mode,
192200
None,
@@ -200,7 +208,7 @@ async def _run_submission(
200208
submission.code,
201209
submission.file_name,
202210
gpu,
203-
RunProgressReporterAPI(f"{gpu.name} on {gpu.runner} (secret)"),
211+
add_reporter(f"{gpu.name} on {gpu.runner} (secret)"),
204212
req.task,
205213
SubmissionMode.PRIVATE,
206214
req.secret_seed,
@@ -212,4 +220,4 @@ async def _run_submission(
212220
with bot.leaderboard_db as db:
213221
db.mark_submission_done(sub_id)
214222

215-
return results
223+
return results, [rep.get_message() + "\n" + rep.long_report for rep in reporters]

0 commit comments

Comments
 (0)