1
0
Fork 0

feat(api): add pending field to image ready response

This commit is contained in:
Sean Sube 2023-03-18 17:25:13 -05:00
parent 15b6e036e1
commit 8cbdad3a71
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
3 changed files with 46 additions and 23 deletions

View File

@ -51,12 +51,17 @@ logger = getLogger(__name__)
def ready_reply(
ready: bool, progress: int = 0, error: bool = False, cancel: bool = False
ready: bool = False,
cancelled: bool = False,
failed: bool = False,
pending: bool = False,
progress: int = 0,
):
return jsonify(
{
"cancel": cancel,
"error": error,
"cancelled": cancelled,
"failed": failed,
"pending": pending,
"progress": progress,
"ready": ready,
}
@ -439,9 +444,9 @@ def cancel(context: ServerContext, pool: DevicePoolExecutor):
return error_reply("output name is required")
output_file = sanitize_name(output_file)
cancel = pool.cancel(output_file)
cancelled = pool.cancel(output_file)
return ready_reply(cancel is not False, cancel=cancel)
return ready_reply(cancelled=cancelled)
def ready(context: ServerContext, pool: DevicePoolExecutor):
@ -450,22 +455,26 @@ def ready(context: ServerContext, pool: DevicePoolExecutor):
return error_reply("output name is required")
output_file = sanitize_name(output_file)
progress = pool.done(output_file)
pending, progress = pool.done(output_file)
if pending:
return ready_reply(pending=True)
if progress is None:
output = base_join(context.output_path, output_file)
if path.exists(output):
return ready_reply(True)
return ready_reply(ready=True)
else:
return ready_reply(
True, error=True
ready=True,
failed=True,
) # is a missing image really an error? yes will display the retry button
return ready_reply(
progress.finished,
ready=progress.finished,
progress=progress.progress,
error=progress.error,
cancel=progress.cancel,
failed=progress.error,
cancelled=progress.cancel,
)

View File

@ -6,8 +6,8 @@ class ProgressCommand:
job: str
finished: bool
progress: int
cancel: bool
error: bool
cancelled: bool
failed: bool
def __init__(
self,
@ -15,15 +15,15 @@ class ProgressCommand:
device: str,
finished: bool,
progress: int,
cancel: bool = False,
error: bool = False,
cancelled: bool = False,
failed: bool = False,
):
self.job = job
self.device = device
self.finished = finished
self.progress = progress
self.cancel = cancel
self.error = error
self.cancelled = cancelled
self.failed = failed
class JobCommand:

View File

@ -232,7 +232,7 @@ class DevicePoolExecutor:
for job in self.pending_jobs:
if job.name == key:
logger.debug("checking status for pending job: %s", key)
return (True, ProgressCommand(job.name, job.device, False, 0))
return (True, None)
logger.trace("checking status for unknown job: %s", key)
return (False, None)
@ -365,25 +365,39 @@ class DevicePoolExecutor:
self.pending_jobs.append(job)
self.pending[device].put(job, block=False)
def status(self) -> List[Tuple[str, int, bool, bool, bool]]:
def status(self) -> List[Tuple[str, int, bool, bool, bool, bool]]:
history = [
(
name,
job.progress,
False,
job.finished,
job.cancel,
job.error,
job.cancelled,
job.failed,
)
for name, job in self.running_jobs.items()
]
history.extend(
[
(
job.name,
0,
True,
False,
False,
False,
) for job in self.pending_jobs
]
)
history.extend(
[
(
job.job,
job.progress,
False,
job.finished,
job.cancel,
job.error,
job.cancelled,
job.failed,
)
for job in self.finished_jobs
]