lint(api): add typed errors from cancelled job and download error
This commit is contained in:
parent
44004730ea
commit
404a314050
|
@ -16,6 +16,7 @@ from packaging import version
|
|||
from torch.onnx import export
|
||||
|
||||
from ..constants import ONNX_WEIGHTS
|
||||
from ..errors import RequestException
|
||||
from ..server import ServerContext
|
||||
from ..utils import get_boolean
|
||||
|
||||
|
@ -103,8 +104,8 @@ def download_progress(urls: List[Tuple[str, str]]):
|
|||
)
|
||||
if req.status_code != 200:
|
||||
req.raise_for_status() # Only works for 4xx errors, per SO answer
|
||||
raise RuntimeError(
|
||||
"Request to %s failed with status code: %s" % (url, req.status_code)
|
||||
raise RequestException(
|
||||
"request to %s failed with status code: %s" % (url, req.status_code)
|
||||
)
|
||||
|
||||
total = int(req.headers.get("Content-Length", 0))
|
||||
|
|
|
@ -4,3 +4,19 @@ class RetryException(Exception):
|
|||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class CancelledException(Exception):
|
||||
"""
|
||||
Used when a job has been cancelled and needs to stop.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class RequestException(Exception):
|
||||
"""
|
||||
Used when an HTTP request has failed.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
|
|
@ -4,6 +4,7 @@ from typing import Any, Callable, Optional
|
|||
|
||||
from torch.multiprocessing import Queue, Value
|
||||
|
||||
from ..errors import CancelledException
|
||||
from ..params import DeviceParams
|
||||
from .command import JobCommand, ProgressCommand
|
||||
|
||||
|
@ -102,7 +103,7 @@ class WorkerContext:
|
|||
raise RuntimeError("no job on which to set progress")
|
||||
|
||||
if self.is_cancelled():
|
||||
raise RuntimeError("job has been cancelled")
|
||||
raise CancelledException("job has been cancelled")
|
||||
|
||||
logger.debug("setting progress for job %s to %s", self.job, progress)
|
||||
self.last_progress = ProgressCommand(
|
||||
|
|
Loading…
Reference in New Issue