-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Make return_immediately configurable for all Pub/Sub modules and mark the setting as deprecated #67621
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
Make return_immediately configurable for all Pub/Sub modules and mark the setting as deprecated #67621
Changes from all commits
3ec7a55
3b5e6dd
c488202
ea7f6c3
e9d18e6
9ce49fd
478e400
f2d9b11
33fdf92
6e9eb67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,15 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
| from collections.abc import Callable, Sequence | ||
| from datetime import timedelta | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from google.cloud import pubsub_v1 | ||
| from google.cloud.pubsub_v1.types import ReceivedMessage | ||
|
|
||
| from airflow.exceptions import AirflowProviderDeprecationWarning | ||
| from airflow.providers.common.compat.sdk import AirflowException, BaseSensorOperator, conf | ||
| from airflow.providers.google.cloud.hooks.pubsub import PubSubHook | ||
| from airflow.providers.google.cloud.triggers.pubsub import PubsubPullTrigger | ||
|
|
@@ -113,7 +115,7 @@ def __init__( | |
| project_id: str, | ||
| subscription: str, | ||
| max_messages: int = 5, | ||
| return_immediately: bool = True, | ||
| return_immediately: bool | None = None, | ||
| ack_messages: bool = False, | ||
| gcp_conn_id: str = "google_cloud_default", | ||
| messages_callback: Callable[[list[ReceivedMessage], Context], Any] | None = None, | ||
|
|
@@ -127,13 +129,21 @@ def __init__( | |
| self.project_id = project_id | ||
| self.subscription = subscription | ||
| self.max_messages = max_messages | ||
| self.return_immediately = return_immediately | ||
| self.ack_messages = ack_messages | ||
| self.messages_callback = messages_callback | ||
| self.impersonation_chain = impersonation_chain | ||
| self.deferrable = deferrable | ||
| self.poke_interval = poke_interval | ||
| self._return_value = None | ||
| if return_immediately is not None: | ||
| warnings.warn( | ||
| "The default value of `return_immediately` will be changed to `False` in a future major release.", | ||
| AirflowProviderDeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
|
Comment on lines
+139
to
+143
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michaelpri10 in google provider we have deprecation policy and by this policy you need to specify planned_removal_date and by default all deprecations should allow a 6 months time period until they will be removed and not available. Could you please add the removal date to this warning message? |
||
| self.return_immediately = return_immediately | ||
| else: | ||
| self.return_immediately = True | ||
|
|
||
| def poke(self, context: Context) -> bool: | ||
| hook = PubSubHook( | ||
|
|
@@ -176,6 +186,7 @@ def execute(self, context: Context) -> None: | |
| poke_interval=self.poke_interval, | ||
| gcp_conn_id=self.gcp_conn_id, | ||
| impersonation_chain=self.impersonation_chain, | ||
| return_immediately=self.return_immediately, | ||
| ), | ||
| method_name="execute_complete", | ||
| ) | ||
|
|
||
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.
@michaelpri10 did you run the system tests for these changes with
return_immediately=False?I am not sure that we should make this parameter configurable for
PubSubPullOperatoras I understand the idea of this operator was return any value immediately include 0 if user does not have any messages. I think it was a reason why we have hardcodedreturn_immediately=Truehere. Otherwise withreturn_immediately=Falseit blocks whole task until message will not appear in my opinion this behavior contradicts with operator logic. If users need blocking waiting for this reason we havePubSubPullSensor.It is the message from docstring to this operator: