-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Adding sensor decorator #22562
Adding sensor decorator #22562
Conversation
airflow/decorators/__init__.pyi
Outdated
@overload | ||
def sensor(self, *, python_callable: Optional[Callable] = None, **kwargs) -> TaskDecorator: | ||
""" | ||
Wraps a Python function into a sensor operator. | ||
:param python_callable: decorated function that implements the poke() logics of a sensor operator. | ||
""" |
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.
Individual arguments should be spelled out explicitly (instead of using kwargs
) since this file is providing editor autocompletion, and kwargs
is mostly useless for autocompletion.
Also, does this make sense?
@sensor # No arguments at all!
def func():
return PokeReturnValue(...)
If not, python_callable
should be removed since that argument is there to specifically support this use case.
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 @uranusjr! I've updated the signature.
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.
The only argument useful for the sensor decorator is "python_callable", but please let me know if there are other arguments that need to be explicit.
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.
@uranusjr I need another +1 to this PR. Could you help take a look again? Thanks!
LGTM. But we need one other approve to merge it. |
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 main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
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.
Is it still in time for 2.3?
I'd say yes - but leave it up to @jedcunningham @ephraimbuddy to decide. |
@ashb @jedcunningham @ephraimbuddy -> shall we add it to 2.3 ? It's a pretty requested feature and seems ready (but I leave it up to you to decide :). |
Fine with me cc: @jedcunningham |
No objections here 👍 |
Someone will need to check how this interacts with task mapping first please |
I think this one is a bit risky to add for 2.3.0 so let's iterate and merge after we branch off. |
Eagerly waiting for this to be merged and released! |
@potiuk Is it OK to merge this PR? |
@mingshi-wang - docs build is failing (that's something that you should fix first) and rebasing the change would also be useful while you do it. Also we are waiting for @jedcunningham 's re-review - just re-requested it. |
I think our Public runners are not big enough to handle "full tests" with k8s :( . So I removed "full tests needed" label and closed/reopened it to run a smaller set of tests |
Thanks for your help! |
HI @jedcunningham I have addressed your comments. Can you take a look again? Thanks! |
Hi @potiuk will you be ok to merge this PR? I see all tests passed. |
We are waiting for @jedcunningham to confirm that he is OK with it - can't merge it without it. |
HI @jedcunningham can you please take a look again? Thanks! |
Hi @potiuk, Jed seems unavailable. Is it possible to get another reviewer? |
Hi @jedcunningham - do you have a chance to take a look? |
Hi @uranusjr @potiuk I think I need some help merging this PR. @jedcunningham is not available to approve this PR. Would you provide some help wrapping up this PR? Thanks! |
I dismissed Jed's review - can you please rebase it @mingshi-wang (there is a conflict) - sorry for long delay - I've been on holidays :). |
I rebased the PR. Could you help merge it? |
Just one more check @uranusjr @jedcunningham ? |
airflow/decorators/__init__.pyi
Outdated
@overload | ||
def sensor(self, **kwargs) -> TaskDecorator: | ||
""" | ||
Wraps a Python function into a sensor operator. | ||
""" |
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.
Can you list out more arguments and the docstring explicitly (like other functions above)? This is shown in editor autocomplete, and the current format is not useful.
@mingshi-wang - I'd love to merge it - can you please address the last comments of @uranusjr ? |
Sure will do. |
348a45b
to
1398b10
Compare
@potiuk @uranusjr I addressed the comments. Could you please take a look again? |
Hi @potiuk are you ok to merge the PR? |
🎉 🎉 - finally @mingshi-wang ! |
from airflow.sensors.python import PythonSensor | ||
|
||
|
||
class DecoratedSensorOperator(PythonSensor): |
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.
Oh, this doesn't inherit from DecoratedOperator -- was there any reason for it not?
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.
(Not a problem I guess, since it's all tested etc.)
Added the @task.sensor decorator to convert a Python function to an instance of the BaseSensorOperator. Example usage of the decorator is:
closes: #20323
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.