-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(sdk): Support using pipeline in exit handlers #8220
Changes from 4 commits
8d0abde
574180d
0a4d340
4d93db6
07932c7
d57c25e
8c9178c
f74ad4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2022 The Kubeflow Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Pipeline using ExitHandler with PipelineTaskFinalStatus.""" | ||
|
||
from kfp import compiler | ||
from kfp import dsl | ||
from kfp.dsl import component | ||
from kfp.dsl import PipelineTaskFinalStatus | ||
|
||
|
||
@component | ||
def print_op(message: str): | ||
"""Prints a message.""" | ||
print(message) | ||
|
||
|
||
@component | ||
def fail_op(message: str): | ||
"""Fails.""" | ||
import sys | ||
print(message) | ||
sys.exit(1) | ||
|
||
|
||
@component | ||
def get_run_state(status: dict) -> str: | ||
print('Pipeline status: ', status) | ||
return status['state'] | ||
|
||
|
||
@dsl.pipeline(name='conditional-notification') | ||
def exit_op(status: PipelineTaskFinalStatus): | ||
"""Checks pipeline run status.""" | ||
with dsl.Condition(get_run_state(status=status).output == 'FAILED'): | ||
print_op(message='notify task failure.') | ||
|
||
|
||
@dsl.pipeline(name='pipeline-with-task-final-status-conditional') | ||
def my_pipeline(message: str = 'Hello World!'): | ||
exit_task = exit_op() | ||
|
||
with dsl.ExitHandler(exit_task, name='my-pipeline'): | ||
print_op(message=message) | ||
fail_op(message='Task failed.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, do we support nested exit handling? For example, there may be ways to handle a failed inner task but let the outer task run as usual. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. While I believe IR can possibly support nested exit handler, I'm not sure if Argo can support it. |
||
|
||
|
||
if __name__ == '__main__': | ||
compiler.Compiler().compile( | ||
pipeline_func=my_pipeline, | ||
package_path=__file__.replace('.py', '.yaml')) |
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.
nit: Should we add an error message? (e.g. Exit task is missing both container spec and pipeline spec)
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.
Updated.