Skip to content
This repository was archived by the owner on Sep 22, 2023. It is now read-only.

Commit b4520c3

Browse files
committed
fix:check background-task in response from manager
1 parent f7fafe5 commit b4520c3

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

changes/181.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Display kernel-pull-progress from background-task-reporter
1+
Display the progress of pulling kernel from reporter of the background task.

src/ai/backend/client/func/session.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -298,27 +298,28 @@ async def get_or_create(
298298
rqst.set_json(params)
299299
async with rqst.fetch() as resp:
300300
data = await resp.json()
301-
with tqdm(total=100, unit='%') as pbar:
302-
task_id = data['background_task']
303-
bgtask = resp.session.BackgroundTask(task_id)
304-
async with bgtask.listen_events() as response:
305-
async for ev in response:
306-
progress = json.loads(ev.data)
307-
if ev.event == 'bgtask_updated':
308-
current = progress['current_progress']
309-
total = progress['total_progress']
310-
if total == 0:
311-
total = 1e-2
312-
pbar.n = round(current / total * 100, 2)
313-
pbar.update(0)
314-
pbar.refresh()
315-
elif ev.event == 'bgtask_done':
316-
pbar.n = 100.0
317-
pbar.update(0)
318-
pbar.refresh()
319-
pbar.clear()
320-
async with rqst.fetch() as resp:
321-
data = await resp.json()
301+
if 'background_task' in data:
302+
with tqdm(total=100, unit='%') as pbar:
303+
task_id = data['background_task']
304+
bgtask = resp.session.BackgroundTask(task_id)
305+
async with bgtask.listen_events() as response:
306+
async for ev in response:
307+
progress = json.loads(ev.data)
308+
if ev.event == 'bgtask_updated':
309+
current = progress['current_progress']
310+
total = progress['total_progress']
311+
if total == 0:
312+
total = 1e-2
313+
pbar.n = round(current / total * 100, 2)
314+
pbar.update(0)
315+
pbar.refresh()
316+
elif ev.event == 'bgtask_done':
317+
pbar.n = 100.0
318+
pbar.update(0)
319+
pbar.refresh()
320+
pbar.clear()
321+
async with rqst.fetch() as resp:
322+
data = await resp.json()
322323
o = cls(name, owner_access_key) # type: ignore
323324
if api_session.get().api_version[0] >= 5:
324325
o.id = UUID(data['sessionId'])

0 commit comments

Comments
 (0)