add wait_policy in EmrCreateJobFlorOperator #61195
Open
+35
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This PR fixes a bug in
EmrCreateJobFlowOperatorwhere thewait_policyparameter was ignored, causing the operator to always default to the JobFlowWaiting waiter (waiting for the cluster to start) regardless of the user's input.The changes include:
Ensuring
wait_policyis correctly persisted in the operator instance.Updating the execute method to select the correct boto3 waiter based on the policy.
Passing the specific waiter name to
EmrCreateJobFlowTriggerto support this logic in deferrable mode.Adding a validation check to prevent users from providing both
wait_for_completionandwait_policysimultaneously.Why
Currently, if a user wants the operator to wait until the EMR cluster finishes all steps and terminates (using
WaitPolicy.WAIT_FOR_STEPS_COMPLETION), the operator fails to do so.It converts the policy to a boolean wait_for_completion = True in
__init__and discards the specific policy type. Consequently, the execute method hardcodes the waiter toWAITER_POLICY_NAME_MAPPING[WaitPolicy.WAIT_FOR_COMPLETION].This behavior causes the task to be marked as "Success" as soon as the cluster enters the WAITING state. If the cluster subsequently fails during a step execution, Airflow does not catch the failure, leading to false positives in DAG runs.
closes: #61180
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.