Skip to content

Commit b32e4e9

Browse files
authored
PubSub: Deprecate several FlowControl settings and things in Message class (googleapis#8796)
* Deprecate several PubSub FlowControl settings * Deprecate things in PubSub message.Message class * Change deprecation release version to 0.44.0
1 parent a5dc557 commit b32e4e9

3 files changed

Lines changed: 50 additions & 12 deletions

File tree

pubsub/google/cloud/pubsub_v1/subscriber/message.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import json
1919
import math
2020
import time
21+
import warnings
2122

2223
from google.api_core import datetime_helpers
2324
from google.cloud.pubsub_v1.subscriber._protocol import requests
@@ -88,6 +89,10 @@ def __init__(self, message, ack_id, request_queue, autolease=True):
8889
autolease (bool): An optional flag determining whether a new Message
8990
instance should automatically lease itself upon creation.
9091
Defaults to :data:`True`.
92+
93+
.. note::
94+
.. deprecated:: 0.44.0
95+
Parameter will be removed in future versions.
9196
"""
9297
self._message = message
9398
self._ack_id = ack_id
@@ -216,7 +221,14 @@ def lease(self):
216221
never need to call it manually, unless the
217222
:class:`~.pubsub_v1.subscriber.message.Message` instance was
218223
created with ``autolease=False``.
224+
225+
.. deprecated:: 0.44.0
226+
Will be removed in future versions.
219227
"""
228+
warnings.warn(
229+
"lease() is deprecated since 0.44.0, and will be removed in future versions.",
230+
category=DeprecationWarning,
231+
)
220232
self._request_queue.put(
221233
requests.LeaseRequest(ack_id=self._ack_id, byte_size=self.size)
222234
)

pubsub/google/cloud/pubsub_v1/types.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import absolute_import
1616
import collections
1717
import sys
18+
import textwrap
1819

1920
from google.api import http_pb2
2021
from google.iam.v1 import iam_policy_pb2
@@ -100,19 +101,41 @@
100101
"The maximum number of received - but not yet processed - messages before "
101102
"pausing the message stream."
102103
)
103-
FlowControl.resume_threshold.__doc__ = (
104-
"The relative threshold of the ``max_bytes`` and ``max_messages`` limits "
105-
"below which to resume the message stream. Must be a positive number not "
106-
"greater than ``1.0``."
104+
FlowControl.resume_threshold.__doc__ = textwrap.dedent(
105+
"""
106+
The relative threshold of the ``max_bytes`` and ``max_messages`` limits
107+
below which to resume the message stream. Must be a positive number not
108+
greater than ``1.0``.
109+
110+
.. note::
111+
.. deprecated:: 0.44.0
112+
Will be removed in future versions."""
107113
)
108-
FlowControl.max_requests.__doc__ = "Currently not in use."
109-
FlowControl.max_request_batch_size.__doc__ = (
110-
"The maximum number of requests scheduled by callbacks to process and "
111-
"dispatch at a time."
114+
FlowControl.max_requests.__doc__ = textwrap.dedent(
115+
"""
116+
Currently not in use.
117+
118+
.. note::
119+
.. deprecated:: 0.44.0
120+
Will be removed in future versions."""
121+
)
122+
FlowControl.max_request_batch_size.__doc__ = textwrap.dedent(
123+
"""
124+
The maximum number of requests scheduled by callbacks to process and
125+
dispatch at a time.
126+
127+
.. note::
128+
.. deprecated:: 0.44.0
129+
Will be removed in future versions."""
112130
)
113-
FlowControl.max_request_batch_latency.__doc__ = (
114-
"The maximum amount of time in seconds to wait for additional request "
115-
"items before processing the next batch of requests."
131+
FlowControl.max_request_batch_latency.__doc__ = textwrap.dedent(
132+
"""
133+
The maximum amount of time in seconds to wait for additional request
134+
items before processing the next batch of requests.
135+
136+
.. note::
137+
.. deprecated:: 0.44.0
138+
Will be removed in future versions."""
116139
)
117140
FlowControl.max_lease_duration.__doc__ = (
118141
"The maximum amount of time in seconds to hold a lease on a message "

pubsub/tests/unit/pubsub_v1/subscriber/test_message.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import time
1717

1818
import mock
19+
import pytest
1920
import pytz
2021
from six.moves import queue
2122
from google.protobuf import timestamp_pb2
@@ -135,7 +136,9 @@ def test_drop():
135136

136137
def test_lease():
137138
msg = create_message(b"foo", ack_id="bogus_ack_id")
138-
with mock.patch.object(msg._request_queue, "put") as put:
139+
140+
pytest_warns = pytest.warns(DeprecationWarning)
141+
with pytest_warns, mock.patch.object(msg._request_queue, "put") as put:
139142
msg.lease()
140143
put.assert_called_once_with(
141144
requests.LeaseRequest(ack_id="bogus_ack_id", byte_size=30)

0 commit comments

Comments
 (0)