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
Add SubprocessHook for running commands from operators #13423
Conversation
5ccafce
to
0583721
Compare
The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*. |
The Workflow run is cancelling this PR. Building image for the PR has been cancelled |
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.
Looks good to me. For few minutes I was considering making this hook stateless and keeping the state in operators but this adds unnecessary complexity.
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
Yes @turbaszek, this is one of the things I was thinking about also. I could not think of a clean way, apart from having BashHook return a "runner" object that has methods I also considered making Another thing I considered was, does it make sense to ensure that In sum, I too think current approach is good enough and now will work on updating docs and possibly tests as necessary. Thanks |
0583721
to
ab010ec
Compare
one material change in latest commit i made I made it so BashHook's run_command will use added / updated tests i left all but one BashOperator test untouched. only this one -- checking the args applied to Popen -- i moved to BashHook. where appropriate, i translated the existing tests for BashHook and copied them there. i will remove WIP designation |
2a0b23d
to
606b60c
Compare
The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*. |
The Workflow run is cancelling this PR. Building image for the PR has been cancelled |
8c93409
to
7f28dd5
Compare
That was also my concern, but I figured that the chance that we will run two processes in parallel in one operator (using one instance of a hook) is low. |
3a11bdc
to
da61f85
Compare
Alright folks... updated to make it shell-agnostic, and to take List[str] I have called it SubprocessHook This is obvs negotiable Options:
Please take a look 🙏 |
SubprocessHook is good. (ShellHook is not because that has a different meaning -- see https://docs.python.org/3/library/subprocess.html#security-considerations) |
thanks and updated 🤞 |
96e3690
to
d4336ba
Compare
Co-authored-by: Tomek Urbaszek <turbaszek@gmail.com>
Co-authored-by: Tomek Urbaszek <turbaszek@gmail.com>
…r only the last line
Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
d4336ba
to
8abc76b
Compare
ok at long last @ashb i think this should be good there seems to be just one test failure in one run which, while i don't see how it could be flakey, does appear to be flakey. it didn't happen in other configurations and doesn't repro locally. perhaps someone could rerun that test? i am hesitant to force push again given how fussy builds have been lately |
Yeah, that's a timing based flakey test. Merging. |
The bash operator has dialed in how to run bash commands from python and airflow.
There are other operators that sometimes need to do this. But for various reasons, they might not want to inherit from BashOperator. And in this case, it would be nice if there were a bash hook that would just let you run a bash command in your operator.
We can also imagine circumstances where perhaps within a single "BashOperator", maybe you want to run a series of bash commands. Well, if you have a hook that encapsulates this functionality, then this is very clean to implement.