Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
amickan committed Oct 23, 2024
1 parent 2a32d52 commit b38dd01
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/grandchallenge/cases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def default_error_message(self):
f"{n_errors} file{pluralize(n_errors)} could not be imported"
)

def get_error_handler(self, linked_object=None):
def get_error_handler(self, *, linked_object=None):
from grandchallenge.algorithms.models import Job

if linked_object:
Expand Down
8 changes: 5 additions & 3 deletions app/grandchallenge/cases/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def build_images( # noqa:C901
)
if linked_interface_slug:
ci = ComponentInterface.objects.get(slug=linked_interface_slug)
else:
ci = None

if linked_object_pk:
try:
Expand Down Expand Up @@ -178,18 +180,18 @@ def build_images( # noqa:C901
except DuplicateFilesException as e:
_delete_session_files(upload_session=upload_session)
error_handler.handle_error(
interface=ci if linked_interface_slug else None,
interface=ci,
error_message=str(e),
)
except (SoftTimeLimitExceeded, TimeLimitExceeded):
error_handler.handle_error(
interface=ci if linked_interface_slug else None,
interface=ci,
error_message="Time limit exceeded",
)
except Exception:
_delete_session_files(upload_session=upload_session)
error_handler.handle_error(
interface=ci if linked_interface_slug else None,
interface=ci,
error_message="An unexpected error occurred",
)
logger.error("An unexpected error occurred", exc_info=True)
Expand Down
2 changes: 1 addition & 1 deletion app/grandchallenge/components/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2435,7 +2435,7 @@ def get_current_value_for_interface(self, *, interface, user):
)
raise e

def get_error_handler(self, linked_object=None):
def get_error_handler(self, *, linked_object=None):
# local imports to prevent circular dependency
from grandchallenge.algorithms.models import Job

Expand Down
2 changes: 1 addition & 1 deletion app/grandchallenge/core/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def handle_error(self, *, error_message, user, interface):
class SystemCIVErrorHandler(ErrorHandler):
def handle_error(self, *, error_message, user, interface):
Notification.send(
kind=NotificationType.NotificationTypeChoices.SYSTEM,
kind=NotificationType.NotificationTypeChoices.CIV_VALIDATION,
message=f"Validation for interface {interface.title} failed.",
description=f"Validation for interface {interface.title} failed: {error_message}",
actor=user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Migration(migrations.Migration):
("JOB-STATUS", "Job status update"),
("IMAGE-IMPORT", "Image import status update"),
("FILE-COPY", "Validation failed while copying file"),
("SYSTEM", "An unexpected error occurred"),
(
"CIV-VALIDATION",
"Component Interface Value validation failed",
),
],
default="GENERIC",
help_text="Of what type is this notification?",
Expand Down
8 changes: 5 additions & 3 deletions app/grandchallenge/notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class NotificationTypeChoices(models.TextChoices):
JOB_STATUS = "JOB-STATUS", _("Job status update")
IMAGE_IMPORT_STATUS = "IMAGE-IMPORT", _("Image import status update")
FILE_COPY_STATUS = "FILE-COPY", _("Validation failed while copying file")
SYSTEM = "SYSTEM", ("An unexpected error occurred")
CIV_VALIDATION = "CIV-VALIDATION", (
"Component Interface Value validation failed"
)


class NotificationType:
Expand Down Expand Up @@ -229,7 +231,7 @@ def get_receivers(*, kind, actor, action_object, target): # noqa: C901
return followers(action_object)
elif kind in [
NotificationType.NotificationTypeChoices.FILE_COPY_STATUS,
NotificationType.NotificationTypeChoices.SYSTEM,
NotificationType.NotificationTypeChoices.CIV_VALIDATION,
]:
return {actor}
else:
Expand Down Expand Up @@ -466,7 +468,7 @@ def print_notification(self, user): # noqa: C901
)
elif self.type in [
NotificationType.NotificationTypeChoices.FILE_COPY_STATUS,
NotificationType.NotificationTypeChoices.SYSTEM,
NotificationType.NotificationTypeChoices.CIV_VALIDATION,
]:
return self.description

Expand Down

0 comments on commit b38dd01

Please sign in to comment.