Skip to content

Commit

Permalink
feat(api): log errors from background jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Feb 4, 2023
1 parent f5039d8 commit 53f4924
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/onnx_web/device_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,14 @@ def submit(self, key: str, fn: Callable[..., None], /, *args, **kwargs) -> None:
job = Job(key, future, context)
self.jobs.append(job)

def job_done(f: Future):
try:
f.result()
logger.info('job %s finished successfully', key)
except Exception as err:
logger.warn('job %s failed with an error: %s', key, err)

future.add_done_callback(job_done)

def status(self) -> Dict[str, Tuple[bool, int]]:
return [(job.key, job.future.done(), job.get_progress()) for job in self.jobs]

0 comments on commit 53f4924

Please sign in to comment.