Gates and Manual Intervention
Gates and Manual Intervention provide mechanisms to introduce human interaction or timed pauses into automated workflows. This capability is crucial for scenarios requiring explicit approvals, data input from an operator, or controlled delays before proceeding with subsequent steps.
Core Features
The Gate class serves as a specialized workflow node designed to pause execution until a specific condition is met, which can be either a user action or a predefined time duration. It supports three primary modes of operation:
-
Approval Gates: These gates halt workflow execution, awaiting explicit confirmation from a user to proceed. They are ideal for critical decision points where human oversight is mandatory.
- An approval gate is typically created by passing an upstream item (e.g., the output of a previous task) to the
Gateconstructor, without specifying aninput_typeorsleep_duration. Thelocal_executemethod will then prompt for confirmation, displaying the value of the upstream item. If the user disapproves, aFlyteDisapprovalExceptionis raised, halting the workflow. - Example: Approving a deployment based on the output of a test run.
- An approval gate is typically created by passing an upstream item (e.g., the output of a previous task) to the
-
Input Gates: These gates pause the workflow to solicit specific data input from a user. The workflow resumes only after the required input, conforming to a specified type, is provided.
- An input gate is instantiated by providing an
input_typeto theGateconstructor. Thepython_interfaceproperty will reflect this input type as the gate's output. During local execution, thelocal_executemethod prompts the user to enter data of the specified type, which then becomes the output of the gate node. - Example: Requesting a user to provide a reason for a rollback or a configuration parameter.
- An input gate is instantiated by providing an
-
Sleep Gates: These gates introduce a controlled delay into the workflow, pausing execution for a specified duration before automatically proceeding. They do not require user interaction.
- A sleep gate is created by setting the
sleep_durationparameter in theGateconstructor. Thelocal_executemethod simulates this pause, and the workflow continues automatically after the duration elapses. - Example: Waiting for an external system to synchronize or for a scheduled maintenance window to pass.
- A sleep gate is created by setting the
Common Use Cases
- Human-in-the-Loop Workflows: Integrate human decision-making into automated processes, such as reviewing machine learning model predictions before deployment or validating sensitive data transformations.
- Staged Deployments and Releases: Implement approval gates between different deployment stages (e.g., dev -> staging -> production) to ensure manual verification and sign-off at each critical juncture.
- Data Curation and Validation: Pause a data pipeline to allow data stewards to inspect and approve data quality, correct anomalies, or provide missing metadata.
- Scheduled Maintenance and Synchronization: Use sleep gates to align workflow execution with external system schedules, ensuring that dependent services are ready or that specific time windows are respected.
- Error Handling and Recovery: Introduce an approval gate after an automated recovery attempt, allowing an operator to confirm the resolution or intervene manually if necessary.
Implementation Details and Considerations
When constructing a Gate instance, the name parameter is mandatory for identifying the gate within the workflow.
- Timeout: All gate types can specify a
timeoutduration. If the required user interaction (for approval or input gates) or the sleep duration is not completed within this timeout, the gate will fail. The default timeout is applied if not explicitly set. - Local Execution: The
local_executemethod provides interactive prompts for input and approval gates during local development and testing, simulating the real-world interaction. For sleep gates, it logs the simulated sleep. - Output Type: For input gates, the
input_typedirectly determines the output type of the gate node, allowing subsequent nodes to consume the user-provided data. Approval and sleep gates typically do not produce a direct output value that is consumed by downstream nodes in the same way, though an approval gate can pass through the approved upstream item. - Error Handling: Disapproval in an approval gate or failure to provide input for an input gate will raise an exception, stopping the workflow at that point. Developers should consider how to handle these exceptions in their workflow design.