-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/on schedule job callback #78
Feature/on schedule job callback #78
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution, I like it!
Added my comments in the review.
ml_client.jobs.stream.side_effect = ValueError() | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you modify this test so that the callback is also mocked?
Pseudo-code:
with #... other patches,
patch("dummy.module:callback") as cb:
# ...
and then assert that cb.assert_called_once()
?
CHANGELOG.md
Outdated
@@ -2,6 +2,8 @@ | |||
|
|||
## [Unreleased] | |||
|
|||
- Added possibility to use custom callbacks with the azureml pipeline job as an argument by [@Gabriel2409](https://github.com/Gabriel2409) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to:
- [Feature 🚀] Added `--on-job-scheduled` argument to `kedro azureml run` to plug-in custom behaviour after Azure ML job is scheduled [@Gabriel2409](https://github.com/Gabriel2409)
I added the changes to the tests. Still regarding the testing, having a module in a helpers folder seems to be the easiest solution: I just need to patch the existing function to ensure it is called exactly once. Moreover, it allows me to test all the cases in dynamic_import_job_schedule_func_from_str` which is what the last case is about. Indeed, using a dummy module meant that I had to patch the Please tell me if this is acceptable for you. |
tests/test_cli.py
Outdated
# extra checks to make sure the tests actually checks the usecase | ||
# and that we are not always in the case of an invalid string | ||
if ":" in on_job_scheduled: | ||
module_str, attr_str = on_job_scheduled.split(":") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not test the code for dynamic_import_job_schedule_func_from_str
at all 🤔 You're effectively validating the arguments passed to the test, not to the downstream invocation (runner.invoke
).
If you want to test this properly, the I would suggest:
- Leave the cases as they are right now:
"on_job_scheduled",
(
"bad_str_format",
"nonexistant_module:func",
"tests.helpers.on_job_scheduled_helper:nonexistant_attr",
"tests.helpers.on_job_scheduled_helper:existing_attr",
),
- Run the
runner.invoke(...)
- Check the
result.exception
against one of the cases that you've specified:
assert result.exit_code != 0
assert result.exception, "Exception should have been raised"
# Rest of the checks
if module_str == "nonexistant_module":
# ... rest of the checks based on the result.execption
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, this is indeed a better solution.
My reasonning was that the only reason the test could fail was because of the --on-job-scheduled arg and I made sure to validate the arguments before the test. Also when checking the code coverage, the function was 100% covered so I figured it was enough.
But I agree with you it is not as robust as checking the error message after invoking the runner. Failure could happen because of something else. I don't know why I didn't think of that as it is the way it is done in another test 🤦♂️
- ``--load-versions`` specifies a particular dataset version (timestamp) for loading (similar behavior as Kedro) | ||
- ``--on-job-scheduled path.to.module:my_function`` specifies a callback function to be called on the azureml pipeline job start (example below) | ||
|
||
.. code:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not display in the docs after rendering (see the screen) 👇🏻
You're probably missing a blank line after .. code:: python
, see the previous usages in the same file above.
https://kedro-azureml--78.org.readthedocs.build/en/78/source/03_quickstart.html
I updated the code based on your remarks. |
Merged, thanks for this feature! |
Hi @marrrcin
Following issue #76 and your comment on PR #77,
here is a proposed implementation for the
--on-job-scheduled
parameter.To use it, you could for example create the following function:
and then run
kedro azureml run --on-job-scheduled mymodule.myfuncs:mycallback
I took inspiration from the way uvicorn allows you to launch an application (
uvicorn main:app
) so the function is specified after a colon.Note that I am not really happy with the way I implemented the unit tests so if you have better ideas, that would be great.