-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for a post_submit callback hook with a simplified…
… signature Signed-off-by: Alex Hughes <[email protected]>
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
) |