|
| 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 | + ) |
0 commit comments