Skip to content

Commit

Permalink
Add initial support for a post_submit callback hook with a simplified…
Browse files Browse the repository at this point in the history
… signature

Signed-off-by: Alex Hughes <[email protected]>
  • Loading branch information
Ahuge committed May 6, 2024
1 parent ce986d0 commit e42db3d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/deadline/client/ui/dialogs/submit_job_to_deadline_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def __init__(
attachments,
)

self._call_ui_hook(initial_job_settings)
if self.on_ui_callback:
self._call_ui_hook(initial_job_settings)

self.gui_update_counter: Any = None
self.refresh_deadline_settings()
Expand Down Expand Up @@ -138,6 +139,11 @@ def refresh(
if hasattr(self.job_settings, "refresh_ui"):
self.job_settings.refresh_ui(job_settings)

def _call_post_submit_hook(self, job_id: str):
self.on_post_submit_callback(
job_id=job_id
)

def _call_ui_hook(self, initial_job_settings):
host_requirements = None
if self.show_host_requirements_tab:
Expand Down Expand Up @@ -515,6 +521,12 @@ def on_submit(self):
auto_accept=str2bool(get_setting("settings.auto_accept")),
require_paths_exist=self.job_attachments.get_require_paths_exist(),
)

# Execute any PostSubmission function defined.
if self.on_post_submit_callback:
self._call_post_submit_hook(
job_id=self.create_job_response["jobId"],
)
except UserInitiatedCancel as uic:
logger.info("Canceling submission.")
QMessageBox.information(self, f"{settings.submitter_name} job submission", str(uic))
Expand Down
7 changes: 7 additions & 0 deletions src/deadline/client/util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

__all__ = ["import_module_function", "validate_function_signature"]

from .callback_loader import import_module_function, validate_function_signature
from .ui_callback import load_ui_callback
from .post_submit_callback import load_post_submit_callback
34 changes: 34 additions & 0 deletions src/deadline/client/util/post_submit_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
The Post Submit Callback is a custom developer callback that can be used to perform actions after a job has been
submitted.
"""
import inspect
from typing import get_type_hints

from .callback_loader import import_module_function, validate_function_signature


def _reference_post_submit_callback_type(
job_id: str,
):
pass


CALLBACK_REFERENCE_SIGNATURE = inspect.signature(_reference_post_submit_callback_type).parameters
CALLBACK_REFERENCE_HINTS = get_type_hints(_reference_post_submit_callback_type)


def load_post_submit_callback(module_path, module_name="post_submit_callback"):
callback = import_module_function(
module_path=module_path,
module_name=module_name,
function_name="on_post_submit_callback",
)
if not validate_function_signature(callback, CALLBACK_REFERENCE_SIGNATURE, hints=CALLBACK_REFERENCE_HINTS):
raise ImportError(
"Python function at {path}:on_post_submit_callback does not match function signature: {signature}."
.format(
path=module_path,
signature=CALLBACK_REFERENCE_SIGNATURE,
)
)

0 comments on commit e42db3d

Please sign in to comment.