Skip to content

Commit

Permalink
improved messaging on MissingConfiguration exception
Browse files Browse the repository at this point in the history
  • Loading branch information
henryborchers committed Dec 8, 2023
1 parent a449f96 commit 13e67b8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
18 changes: 18 additions & 0 deletions speedwagon/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ class MissingConfiguration(SpeedwagonException):

description = "Missing required configuration settings"

def __init__(
self,
message: Optional[str] = None,
workflow: Optional[str] = None,
key: Optional[str] = None
):
"""Create a new exception.
Args:
message: Message presented by exception
workflow: Name of the workflow that contains the missing value
key: Config key that is missing
"""
super().__init__(message)
self.message = message
self.workflow = workflow
self.key = key


class JobCancelled(Exception):
"""Job cancelled exception."""
Expand Down
19 changes: 19 additions & 0 deletions speedwagon/runner_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,29 @@ def run_job_on_thread(
total=task_scheduler.total_tasks,
)
liaison.callbacks.finished(JobSuccess.SUCCESS)

except speedwagon.exceptions.JobCancelled as job_cancelled:
liaison.callbacks.finished(JobSuccess.ABORTED)
logging.debug("Job canceled: %s", job_cancelled)

except speedwagon.exceptions.MissingConfiguration as config_error:
liaison.callbacks.finished(JobSuccess.ABORTED)
if config_error.key and config_error.workflow:
logging.debug(
'Unable to start job with missing configurations: '
'"%s" from "%s". '
'\nCheck the Workflow Settings section in '
'Speedwagon settings.',
config_error.key, config_error.workflow
)
else:
logging.debug(
'Unable to start job with missing configurations. '
'\nReason: %s'
'\nCheck the Workflow Settings section in '
'Speedwagon settings.',
config_error
)
except BaseException as exception_thrown:
traceback_info = traceback.format_exc()

Expand Down
8 changes: 6 additions & 2 deletions speedwagon/workflows/workflow_get_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class JobArgs(typing.TypedDict):
"Identifier type": str,
},
)
GETMARC_SERVER_URL_CONFIG = "Getmarc server url"


class GenerateMarcXMLFilesWorkflow(speedwagon.Workflow):
Expand Down Expand Up @@ -164,7 +165,7 @@ def get_marc_server(self) -> Optional[str]:
"""Get the server url from the configuration."""
return typing.cast(
Optional[str],
self.get_workflow_configuration_value("Getmarc server url"),
self.get_workflow_configuration_value(GETMARC_SERVER_URL_CONFIG),
)

def discover_task_metadata(
Expand All @@ -187,7 +188,10 @@ def discover_task_metadata(
_user_args = cast(UserArgs, user_args)
server_url = self.get_marc_server()
if server_url is None:
raise MissingConfiguration("Getmarc server url is not set")
raise MissingConfiguration(
workflow=self.name,
key=GETMARC_SERVER_URL_CONFIG
)

search_path = _user_args["Input"]
jobs: List[Dict[str, Union[str, Collection[str]]]] = [
Expand Down

0 comments on commit 13e67b8

Please sign in to comment.