Skip to content

Commit 8a325cb

Browse files
author
Dewen Qi
committed
feature: Add FailStep Support for Sagemaker Pipeline
change: Add tests for Fail step API model change
1 parent 34b07c0 commit 8a325cb

File tree

5 files changed

+513
-0
lines changed

5 files changed

+513
-0
lines changed

doc/workflows/pipelines/sagemaker.workflow.pipelines.rst

+2
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,5 @@ Steps
149149
.. autoclass:: sagemaker.workflow.clarify_check_step.ClarifyCheckConfig
150150

151151
.. autoclass:: sagemaker.workflow.clarify_check_step.ClarifyCheckStep
152+
153+
.. autoclass:: sagemaker.workflow.fail_step.FailStep

src/sagemaker/workflow/fail_step.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""The step definitions for workflow."""
14+
from __future__ import absolute_import
15+
16+
from typing import List, Union
17+
18+
from sagemaker.workflow import PipelineNonPrimitiveInputTypes
19+
from sagemaker.workflow.entities import (
20+
RequestType,
21+
)
22+
from sagemaker.workflow.steps import Step, StepTypeEnum
23+
24+
25+
class FailStep(Step):
26+
"""Fail step for workflow."""
27+
28+
def __init__(
29+
self,
30+
name: str,
31+
error_message: Union[str, PipelineNonPrimitiveInputTypes] = None,
32+
display_name: str = None,
33+
description: str = None,
34+
depends_on: Union[List[str], List[Step]] = None,
35+
):
36+
"""Constructs a FailStep.
37+
38+
Args:
39+
name (str): The name of the Fail step.
40+
error_message (str or PipelineNonPrimitiveInputTypes): Error message defined by user.
41+
Once the Fail step is reached the execution will fail and the
42+
error message will be set as the failure reason (default: None).
43+
display_name (str): The display name of the Fail step (default: None).
44+
description (str): The description of the Fail step (default: None).
45+
depends_on (List[str] or List[Step]): A list of step names or step instances
46+
this `sagemaker.workflow.steps.FailStep` depends on (default: None).
47+
"""
48+
super(FailStep, self).__init__(
49+
name, display_name, description, StepTypeEnum.FAIL, depends_on
50+
)
51+
self.error_message = error_message if error_message is not None else ""
52+
53+
@property
54+
def arguments(self) -> RequestType:
55+
"""The arguments dict that is used to define the Fail step."""
56+
return dict(ErrorMessage=self.error_message)
57+
58+
@property
59+
def properties(self):
60+
"""A Properties object is not available for the Fail step"""
61+
raise RuntimeError(
62+
"The Properties object is not available for the Fail step "
63+
+ "as it cannot be referenced by other steps."
64+
)

src/sagemaker/workflow/steps.py

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class StepTypeEnum(Enum, metaclass=DefaultEnumMeta):
6161
QUALITY_CHECK = "QualityCheck"
6262
CLARIFY_CHECK = "ClarifyCheck"
6363
EMR = "EMR"
64+
FAIL = "Fail"
6465

6566

6667
@attr.s

0 commit comments

Comments
 (0)