Add spawner progress message
This commit is contained in:
parent
8574a75e37
commit
77b4c64f88
6 changed files with 186 additions and 4 deletions
54
src/glicid_spawner/progress.py
Normal file
54
src/glicid_spawner/progress.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
"""Progress messages module."""
|
||||
|
||||
from batchspawner import JobStatus
|
||||
|
||||
|
||||
def jhp(progress, message):
|
||||
"""Jupyterhub progress message dictionary."""
|
||||
return {'progress': progress, 'message': message}
|
||||
|
||||
|
||||
class Process:
|
||||
"""Progress value."""
|
||||
|
||||
ERROR = jhp(0, '💀 Oops something when wrong')
|
||||
SUBMIT = jhp(10, '📝 Job submitted')
|
||||
PENDING = jhp(20, '⏱️ Your job is pending in queue')
|
||||
INIT = jhp(40, '📦 The resources were allocated')
|
||||
SETUP = jhp(60, '🏗️ Setting up your environment (it should take a minute or two)')
|
||||
CONNECT = jhp(80, '📡 Be ready you should be connected at any moment')
|
||||
TOO_LONG = jhp(95, '🧐 Your instance takes longer than usual but it should be ready soon')
|
||||
|
||||
|
||||
class ElapseTime:
|
||||
"""Elapse time steps when the job is running."""
|
||||
|
||||
SUBMIT = 0
|
||||
PENDING = 0
|
||||
INIT = 10
|
||||
SETUP = 30
|
||||
CONNECT = 60
|
||||
|
||||
|
||||
def get_progress(job_status: JobStatus, elapse_time: int) -> dict: # noqa: PLR0911 (too-many-return-statements)
|
||||
"""Progress and message based on job status and elapse time."""
|
||||
match job_status:
|
||||
case JobStatus.NOTFOUND:
|
||||
return Process.SUBMIT
|
||||
|
||||
case JobStatus.PENDING:
|
||||
return Process.PENDING
|
||||
|
||||
case JobStatus.RUNNING:
|
||||
if elapse_time < ElapseTime.INIT:
|
||||
return Process.INIT
|
||||
|
||||
if elapse_time < ElapseTime.SETUP:
|
||||
return Process.SETUP
|
||||
|
||||
if elapse_time < ElapseTime.CONNECT:
|
||||
return Process.CONNECT
|
||||
|
||||
return Process.TOO_LONG
|
||||
|
||||
return Process.ERROR
|
|
@ -1,11 +1,13 @@
|
|||
"""GLiCID spawner module."""
|
||||
|
||||
import asyncio
|
||||
import re
|
||||
|
||||
from batchspawner import SlurmSpawner
|
||||
from traitlets import Unicode, default
|
||||
from batchspawner import JobStatus, SlurmSpawner
|
||||
from traitlets import Integer, Unicode, default
|
||||
|
||||
from .form import options_form, options_from_form
|
||||
from .progress import ElapseTime, get_progress
|
||||
|
||||
|
||||
class GlicidSpawner(SlurmSpawner):
|
||||
|
@ -44,3 +46,27 @@ class GlicidSpawner(SlurmSpawner):
|
|||
def options_from_form(self, formdata) -> dict:
|
||||
"""Export options from form."""
|
||||
return options_from_form(formdata)
|
||||
|
||||
progress_rate = Integer(
|
||||
5, help='Interval in seconds at which progress is polled for messages'
|
||||
).tag(config=True)
|
||||
|
||||
async def progress(self):
|
||||
"""Progress bar feedback."""
|
||||
elapse_time = 0
|
||||
|
||||
while True:
|
||||
if self.state_isrunning():
|
||||
job_status = JobStatus.RUNNING
|
||||
elapse_time += self.progress_rate
|
||||
elif self.state_ispending():
|
||||
job_status = JobStatus.PENDING
|
||||
else:
|
||||
job_status = JobStatus.NOTFOUND
|
||||
|
||||
yield get_progress(job_status, elapse_time)
|
||||
|
||||
if elapse_time >= ElapseTime.CONNECT:
|
||||
break
|
||||
|
||||
await asyncio.sleep(self.progress_rate)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue