Skip to content

Commit

Permalink
fix: prevent queueing or killing external jobs (#100)
Browse files Browse the repository at this point in the history
Raises error message sooner
  • Loading branch information
nfrasser authored Nov 5, 2024
1 parent 029d68b commit 688c705
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cryosparc/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ def __init__(self, caller: str, validation: SlotsValidation):
)

return super().__init__(msg)


class ExternalJobError(Exception):
"""
Raised during external job lifecycle failures
"""

pass
18 changes: 15 additions & 3 deletions cryosparc/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from .command import CommandError, make_json_request, make_request
from .dataset import DEFAULT_FORMAT, Dataset
from .errors import InvalidSlotsError
from .errors import ExternalJobError, InvalidSlotsError
from .spec import (
ASSET_CONTENT_TYPES,
IMAGE_CONTENT_TYPES,
Expand Down Expand Up @@ -1572,12 +1572,24 @@ def run(self):
"""
error = False
self.start("running")
self.refresh()
try:
yield self
except Exception:
error = True
raise
finally:
self.stop(error) # TODO: Write Error to job log, if possible
self.refresh()

def queue(
self,
lane: Optional[str] = None,
hostname: Optional[str] = None,
gpus: List[int] = [],
cluster_vars: Dict[str, Any] = {},
):
raise ExternalJobError(
"Cannot queue an external job; use `job.start()`/`job.stop()` or `with job.run()` instead"
)

def kill(self):
raise ExternalJobError("Cannot kill an external job; use `job.stop()` instead")

0 comments on commit 688c705

Please sign in to comment.