Skip to content
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

Merged
merged 1 commit into from
Nov 7, 2022
Merged

Adding sensor decorator #22562

merged 1 commit into from
Nov 7, 2022

Conversation

mingshi-wang
Copy link
Contributor

@mingshi-wang mingshi-wang commented Mar 28, 2022

Added the @task.sensor decorator to convert a Python function to an instance of the BaseSensorOperator. Example usage of the decorator is:

@task.sensor(poke_interval=60, timeout=3600, mode="poke")
def f() -> PokeReturnValue:
    # implement the condition 
    condition_met = ...
    operator_return_value = ...
    return PokeReturnValue(is_done=condition_met, xcom_value=operator_return_value)

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.

Comment on lines 250 to 447
@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.
"""
Copy link
Member

@uranusjr uranusjr Mar 28, 2022

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

@potiuk
Copy link
Member

potiuk commented Mar 31, 2022

LGTM. But we need one other approve to merge it.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Mar 31, 2022
@github-actions
Copy link

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.

Copy link
Member

@uranusjr uranusjr left a 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?

@potiuk
Copy link
Member

potiuk commented Apr 9, 2022

Is it still in time for 2.3?

I'd say yes - but leave it up to @jedcunningham @ephraimbuddy to decide.

@potiuk
Copy link
Member

potiuk commented Apr 13, 2022

@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 :).

@ephraimbuddy
Copy link
Contributor

Fine with me cc: @jedcunningham

@jedcunningham
Copy link
Member

No objections here 👍

airflow/example_dags/example_sensor_decorator.py Outdated Show resolved Hide resolved
@ashb
Copy link
Member

ashb commented Apr 14, 2022

Someone will need to check how this interacts with task mapping first please

@potiuk
Copy link
Member

potiuk commented Apr 25, 2022

I think this one is a bit risky to add for 2.3.0 so let's iterate and merge after we branch off.

@abhilash1in
Copy link
Contributor

Eagerly waiting for this to be merged and released!

@mingshi-wang
Copy link
Contributor Author

@potiuk Is it OK to merge this PR?

@potiuk potiuk requested a review from jedcunningham June 4, 2022 16:40
@potiuk
Copy link
Member

potiuk commented Jun 4, 2022

@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.

@potiuk
Copy link
Member

potiuk commented Sep 20, 2022

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

@mingshi-wang
Copy link
Contributor Author

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!

@mingshi-wang
Copy link
Contributor Author

HI @jedcunningham I have addressed your comments. Can you take a look again? Thanks!

@mingshi-wang
Copy link
Contributor Author

Hi @potiuk will you be ok to merge this PR? I see all tests passed.

@potiuk
Copy link
Member

potiuk commented Sep 22, 2022

We are waiting for @jedcunningham to confirm that he is OK with it - can't merge it without it.

@mingshi-wang
Copy link
Contributor Author

HI @jedcunningham can you please take a look again? Thanks!

@mingshi-wang
Copy link
Contributor Author

We are waiting for @jedcunningham to confirm that he is OK with it - can't merge it without it.

Hi @potiuk, Jed seems unavailable. Is it possible to get another reviewer?

@mingshi-wang
Copy link
Contributor Author

Hi @jedcunningham - do you have a chance to take a look?

@mingshi-wang
Copy link
Contributor Author

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!

@potiuk
Copy link
Member

potiuk commented Oct 23, 2022

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 :).

@mingshi-wang
Copy link
Contributor Author

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?

@potiuk
Copy link
Member

potiuk commented Oct 26, 2022

Just one more check @uranusjr @jedcunningham ?

Comment on lines 415 to 447
@overload
def sensor(self, **kwargs) -> TaskDecorator:
"""
Wraps a Python function into a sensor operator.
"""
Copy link
Member

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.

@potiuk potiuk added this to the Airflow 2.5.0 milestone Oct 31, 2022
@potiuk
Copy link
Member

potiuk commented Oct 31, 2022

@mingshi-wang - I'd love to merge it - can you please address the last comments of @uranusjr ?

@mingshi-wang
Copy link
Contributor Author

@mingshi-wang - I'd love to merge it - can you please address the last comments of @uranusjr ?

Sure will do.

@mingshi-wang
Copy link
Contributor Author

mingshi-wang commented Nov 1, 2022

@mingshi-wang - I'd love to merge it - can you please address the last comments of @uranusjr?

@potiuk @uranusjr I addressed the comments. Could you please take a look again?

@mingshi-wang
Copy link
Contributor Author

@mingshi-wang - I'd love to merge it - can you please address the last comments of @uranusjr ?

Hi @potiuk are you ok to merge the PR?

@potiuk potiuk merged commit cfd63df into apache:main Nov 7, 2022
@potiuk
Copy link
Member

potiuk commented Nov 7, 2022

🎉 🎉 - finally @mingshi-wang !

@ephraimbuddy ephraimbuddy added the type:new-feature Changelog: New Features label Nov 16, 2022
from airflow.sensors.python import PythonSensor


class DecoratedSensorOperator(PythonSensor):
Copy link
Member

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?

Copy link
Member

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a @task.sensor TaskFlow decorator
8 participants