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

feat: Display kernel-pull-progress #181

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/181.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display kernel-pull-progress from background-task-reporter
21 changes: 21 additions & 0 deletions src/ai/backend/client/func/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,27 @@ async def get_or_create(
rqst.set_json(params)
async with rqst.fetch() as resp:
data = await resp.json()
with tqdm(total=100, unit='%') as pbar:
task_id = data['background_task']
bgtask = resp.session.BackgroundTask(task_id)
async with bgtask.listen_events() as response:
async for ev in response:
progress = json.loads(ev.data)
if ev.event == 'bgtask_updated':
current = progress['current_progress']
total = progress['total_progress']
if total == 0:
total = 1e-2
pbar.n = round(current / total * 100, 2)
pbar.update(0)
pbar.refresh()
elif ev.event == 'bgtask_done':
pbar.n = 100.0
pbar.update(0)
pbar.refresh()
pbar.clear()
async with rqst.fetch() as resp:
data = await resp.json()
o = cls(name, owner_access_key) # type: ignore
if api_session.get().api_version[0] >= 5:
o.id = UUID(data['sessionId'])
Expand Down