-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Made WinRMOperator deferrable #60651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds deferrable execution support to the WinRMOperator to address issues where long-running remote Windows processes were causing TaskInstances to be prematurely killed by the scheduler. The refactoring introduces asynchronous polling via a new trigger, freeing workers from blocking on command completion.
Changes:
- Introduced
WinRMCommandOutputTriggerfor asynchronous polling of WinRM command output - Refactored
WinRMOperatorto support deferrable mode with newexecute_completecallback - Restructured
WinRMHookto separate command execution from output polling
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/triggers/winrm.py |
New trigger implementation for async command output polling |
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/operators/winrm.py |
Added deferrable mode support and refactored execute logic |
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/hooks/winrm.py |
Extracted command execution and output polling into separate methods |
providers/microsoft/winrm/tests/unit/microsoft/winrm/triggers/test_winrm.py |
Unit tests for the new trigger |
providers/microsoft/winrm/tests/unit/microsoft/winrm/operators/test_winrm.py |
Updated operator tests with deferrable mode coverage |
providers/microsoft/winrm/tests/unit/microsoft/winrm/hooks/test_winrm.py |
Simplified import statement |
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/get_provider_info.py |
Registered the new trigger module |
providers/microsoft/winrm/provider.yaml |
Added trigger configuration |
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/triggers/__init__.py |
New init file for triggers module |
providers/microsoft/winrm/tests/unit/microsoft/winrm/triggers/__init__.py |
New init file for trigger tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/triggers/winrm.py
Show resolved
Hide resolved
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/hooks/winrm.py
Outdated
Show resolved
Hide resolved
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/operators/winrm.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have a few comments below.
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/hooks/winrm.py
Outdated
Show resolved
Hide resolved
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/operators/winrm.py
Show resolved
Hide resolved
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/triggers/winrm.py
Show resolved
Hide resolved
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/triggers/winrm.py
Show resolved
Hide resolved
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/operators/winrm.py
Outdated
Show resolved
Hide resolved
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/operators/winrm.py
Outdated
Show resolved
Hide resolved
…m/hooks/winrm.py Co-authored-by: Copilot <[email protected]>
…m/operators/winrm.py Co-authored-by: Copilot <[email protected]>
…lised" This reverts commit 5917787.
Was generative AI tooling used to co-author this PR?
Motivation
Recently, we encountered an issue where TaskInstances were being prematurely killed by the scheduler.
We initially tried the fix proposed in PR #60330 made by @ephraimbuddy, but unfortunately this did not help in our case. After further investigation, we discovered that this behaviour only occurred in DAGs using the WinRMOperator.
Problem
We use the WinRMOperator to launch remote processes on Windows servers. Some of these processes can take a significant amount of time to complete.
The root cause is that the WinRMOperator currently performs polling synchronously inside the worker, via the run method of WinRMHook. This has several drawbacks:
Overall, this is not an efficient or scalable execution model in Airflow.
Solution
This PR refactors the WinRMOperator to support deferrable execution.
When deferrable=True:
This aligns the WinRMOperator with Airflow’s recommended architecture for long-running or polling-based operations.
Benefits
Workers are no longer blocked by long-running WinRM commands.
Example Usage
Conclussion
With this refactoring in place, we no longer experience TaskInstances being prematurely killed. Polling is handled asynchronously by the triggerer, which is the preferred and more robust approach for this type of workload in Airflow and we don't block workers for polling unnecessarily.
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.