我如何获得上一个工作阶段的状态

时间:2020-10-01 21:27:05

标签: python-3.x kubeflow kubeflow-pipelines kfp

在继续下一项工作之前,我必须对工作流程中的上一项工作进行验证,因此我认为我必须获得上一项工作的阶段状态,例如

{{workflow.status}}

从这份工作

data-pipeline-mmqvw.exit-handler-1.intentional-fail

我需要获取阶段状态,并且如果这项工作失败或成功了,我需要做一个try catch,我必须继续下一个工作。 我该怎么办?

代码:

#!/usr/bin/env python3
from typing import NamedTuple
import kfp
from kfp.components import func_to_container_op, InputPath, OutputPath
from kubernetes.client.models import (
    V1Volume,
    V1SecretVolumeSource,
    V1EnvFromSource,
    V1EnvVar,
    V1EnvVarSource,
    V1SecretKeySelector,
    V1SecretReference,
)


def curl_container(notify_command: str):
    return (
        kfp.dsl.ContainerOp(
            "show-report",
            image="curlimages/curl:latest",
            command=["ash", "-c"],
            arguments=[f"echo {notify_command}"],
        )
    )


def container_fail():
    return (
        kfp.dsl.ContainerOp(
            "intentional-fail",
            image="alpine:latest",
            command=["sh", "-c"],
            arguments=["echo intentional failure"],
        )
    )


@func_to_container_op
def print_data(message: str):
    import logging
    logging.basicConfig(level=logging.INFO)
    print(message)


@kfp.dsl.pipeline(
    name='DATA_PIPELINE',
    description='get data cdmx'
)
def data_pipeline():
    workflow_name = "{{workflow.name}}"
    workflow_status = "{{workflow.status}}"
    workflow_namespace = "{{workflow.namespace}}"
    
    
    print_dt = print_data(workflow_status)
    with kfp.dsl.ExitHandler(print_dt):
        con_fail = container_fail()
        curl_coint = curl_container("hola")
        curl_coint.after(con_fail)


if __name__ == '__main__':
    kfp.compiler.Compiler().compile(data_pipeline, __file__ + '.yaml')

enter image description here

0 个答案:

没有答案