Skip to content

Commit 719135a

Browse files
authored
Remove references to deprecated operators/params in PubSub operators (#22519)
1 parent ca4b8d1 commit 719135a

File tree

1 file changed

+57
-65
lines changed
  • airflow/providers/google/cloud/operators

1 file changed

+57
-65
lines changed

β€Žairflow/providers/google/cloud/operators/pubsub.py

Lines changed: 57 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,23 @@ class PubSubCreateTopicOperator(BaseOperator):
5555
5656
with DAG('successful DAG') as dag:
5757
(
58-
PubSubTopicCreateOperator(project='my-project',
59-
topic='my_new_topic')
60-
>> PubSubTopicCreateOperator(project='my-project',
61-
topic='my_new_topic')
58+
PubSubCreateTopicOperator(project_id='my-project', topic='my_new_topic')
59+
>> PubSubCreateTopicOperator(project_id='my-project', topic='my_new_topic')
6260
)
6361
6462
The operator can be configured to fail if the topic already exists. ::
6563
6664
with DAG('failing DAG') as dag:
6765
(
68-
PubSubTopicCreateOperator(project='my-project',
69-
topic='my_new_topic')
70-
>> PubSubTopicCreateOperator(project='my-project',
71-
topic='my_new_topic',
72-
fail_if_exists=True)
66+
PubSubCreateTopicOperator(project_id='my-project', topic='my_new_topic')
67+
>> PubSubCreateTopicOperator(
68+
project_id='my-project',
69+
topic='my_new_topic',
70+
fail_if_exists=True,
71+
)
7372
)
7473
75-
Both ``project`` and ``topic`` are templated so you can use
76-
variables in them.
74+
Both ``project_id`` and ``topic`` are templated so you can use Jinja templating in their values.
7775
7876
:param project_id: Optional, the Google Cloud project ID where the topic will be created.
7977
If set to None or missing, the default project_id from the Google Cloud connection is used.
@@ -192,47 +190,53 @@ class PubSubCreateSubscriptionOperator(BaseOperator):
192190
For more information on how to use this operator, take a look at the guide:
193191
:ref:`howto/operator:PubSubCreateSubscriptionOperator`
194192
195-
By default, the subscription will be created in ``topic_project``. If
196-
``subscription_project`` is specified and the Google Cloud credentials allow, the
193+
By default, the subscription will be created in ``project_id``. If
194+
``subscription_project_id`` is specified and the Google Cloud credentials allow, the
197195
Subscription can be created in a different project from its topic.
198196
199197
By default, if the subscription already exists, this operator will
200198
not cause the DAG to fail. However, the topic must exist in the project. ::
201199
202200
with DAG('successful DAG') as dag:
203201
(
204-
PubSubSubscriptionCreateOperator(
205-
topic_project='my-project', topic='my-topic',
206-
subscription='my-subscription')
207-
>> PubSubSubscriptionCreateOperator(
208-
topic_project='my-project', topic='my-topic',
209-
subscription='my-subscription')
202+
PubSubCreateSubscriptionOperator(
203+
project_id='my-project',
204+
topic='my-topic',
205+
subscription='my-subscription'
206+
)
207+
>> PubSubCreateSubscriptionOperator(
208+
project_id='my-project',
209+
topic='my-topic',
210+
subscription='my-subscription',
211+
)
210212
)
211213
212214
The operator can be configured to fail if the subscription already exists.
213215
::
214216
215217
with DAG('failing DAG') as dag:
216218
(
217-
PubSubSubscriptionCreateOperator(
218-
topic_project='my-project', topic='my-topic',
219-
subscription='my-subscription')
220-
>> PubSubSubscriptionCreateOperator(
221-
topic_project='my-project', topic='my-topic',
222-
subscription='my-subscription', fail_if_exists=True)
219+
PubSubCreateSubscriptionOperator(
220+
project_id='my-project',
221+
topic='my-topic',
222+
subscription='my-subscription',
223+
)
224+
>> PubSubCreateSubscriptionOperator(
225+
project_id='my-project',
226+
topic='my-topic',
227+
subscription='my-subscription',
228+
fail_if_exists=True,
229+
)
223230
)
224231
225232
Finally, subscription is not required. If not passed, the operator will
226233
generated a universally unique identifier for the subscription's name. ::
227234
228235
with DAG('DAG') as dag:
229-
(
230-
PubSubSubscriptionCreateOperator(
231-
topic_project='my-project', topic='my-topic')
232-
)
236+
PubSubCreateSubscriptionOperator(project_id='my-project', topic='my-topic')
233237
234-
``topic_project``, ``topic``, ``subscription``, ``subscription_project_id`` and
235-
``impersonation_chain`` are templated so you can use variables in them.
238+
``project_id``, ``topic``, ``subscription``, ``subscription_project_id`` and
239+
``impersonation_chain`` are templated so you can use Jinja templating in their values.
236240
237241
:param project_id: Optional, the Google Cloud project ID where the topic exists.
238242
If set to None or missing, the default project_id from the Google Cloud connection is used.
@@ -357,8 +361,8 @@ def __init__(
357361
project_id = topic_project
358362
if subscription_project:
359363
warnings.warn(
360-
"The project_id parameter has been deprecated. You should pass "
361-
"the subscription_project parameter.",
364+
"The subscription_project parameter has been deprecated. You should pass "
365+
"the subscription_project_id parameter.",
362366
DeprecationWarning,
363367
stacklevel=2,
364368
)
@@ -431,22 +435,16 @@ class PubSubDeleteTopicOperator(BaseOperator):
431435
not cause the DAG to fail. ::
432436
433437
with DAG('successful DAG') as dag:
434-
(
435-
PubSubTopicDeleteOperator(project='my-project',
436-
topic='non_existing_topic')
437-
)
438+
PubSubDeleteTopicOperator(project_id='my-project', topic='non_existing_topic')
438439
439440
The operator can be configured to fail if the topic does not exist. ::
440441
441442
with DAG('failing DAG') as dag:
442-
(
443-
PubSubTopicCreateOperator(project='my-project',
444-
topic='non_existing_topic',
445-
fail_if_not_exists=True)
443+
PubSubDeleteTopicOperator(
444+
project_id='my-project', topic='non_existing_topic', fail_if_not_exists=True,
446445
)
447446
448-
Both ``project`` and ``topic`` are templated so you can use
449-
variables in them.
447+
Both ``project_id`` and ``topic`` are templated so you can use Jinja templating in their values.
450448
451449
:param project_id: Optional, the Google Cloud project ID in which to work (templated).
452450
If set to None or missing, the default project_id from the Google Cloud connection is used.
@@ -551,24 +549,18 @@ class PubSubDeleteSubscriptionOperator(BaseOperator):
551549
not cause the DAG to fail. ::
552550
553551
with DAG('successful DAG') as dag:
554-
(
555-
PubSubSubscriptionDeleteOperator(project='my-project',
556-
subscription='non-existing')
557-
)
552+
PubSubDeleteSubscriptionOperator(project_id='my-project', subscription='non-existing')
558553
559554
The operator can be configured to fail if the subscription already exists.
560555
561556
::
562557
563558
with DAG('failing DAG') as dag:
564-
(
565-
PubSubSubscriptionDeleteOperator(
566-
project='my-project', subscription='non-existing',
567-
fail_if_not_exists=True)
559+
PubSubDeleteSubscriptionOperator(
560+
project_id='my-project', subscription='non-existing', fail_if_not_exists=True,
568561
)
569562
570-
``project``, and ``subscription`` are templated so you can use
571-
variables in them.
563+
``project_id``, and ``subscription`` are templated so you can use Jinja templating in their values.
572564
573565
:param project_id: Optional, the Google Cloud project ID in which to work (templated).
574566
If set to None or missing, the default project_id from the Google Cloud connection is used.
@@ -679,14 +671,16 @@ class PubSubPublishMessageOperator(BaseOperator):
679671
m2 = {'data': b'Knock, knock'}
680672
m3 = {'attributes': {'foo': ''}}
681673
682-
t1 = PubSubPublishOperator(
683-
project='my-project',topic='my_topic',
674+
t1 = PubSubPublishMessageOperator(
675+
project_id='my-project',
676+
topic='my_topic',
684677
messages=[m1, m2, m3],
685678
create_topic=True,
686-
dag=dag)
679+
dag=dag,
680+
)
687681
688-
``project`` , ``topic``, and ``messages`` are templated so you can use
689-
variables in them.
682+
``project_id``, ``topic``, and ``messages`` are templated so you can use Jinja templating
683+
in their values.
690684
691685
:param project_id: Optional, the Google Cloud project ID in which to work (templated).
692686
If set to None or missing, the default project_id from the Google Cloud connection is used.
@@ -775,22 +769,20 @@ class PubSubPullOperator(BaseOperator):
775769
instead.
776770
777771
.. seealso::
778-
For more information on how to use this operator, take a look at the guide:
772+
For more information on how to use this operator and the PubSubPullSensor, take a look at the guide:
779773
:ref:`howto/operator:PubSubPullSensor`
780774
781-
This sensor operator will pull up to ``max_messages`` messages from the
775+
This operator will pull up to ``max_messages`` messages from the
782776
specified PubSub subscription. When the subscription returns messages,
783-
the poke method's criteria will be fulfilled and the messages will be
784-
returned from the operator and passed through XCom for downstream tasks.
777+
the messages will be returned immediately from the operator and passed through XCom for downstream tasks.
785778
786779
If ``ack_messages`` is set to True, messages will be immediately
787780
acknowledged before being returned, otherwise, downstream tasks will be
788781
responsible for acknowledging them.
789782
790-
``project`` and ``subscription`` are templated so you can use
791-
variables in them.
783+
``project_id `` and ``subscription`` are templated so you can use Jinja templating in their values.
792784
793-
:param project: the Google Cloud project ID for the subscription (templated)
785+
:param project_id: the Google Cloud project ID for the subscription (templated)
794786
:param subscription: the Pub/Sub subscription name. Do not include the
795787
full subscription path.
796788
:param max_messages: The maximum number of messages to retrieve per

0 commit comments

Comments
 (0)