Add loan-advisor-agent (part 6)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/_sequencer/ordered_sequencer.py +339 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/_sequencer/unordered_sequencer.py +165 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/client.py +615 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/exceptions.py +52 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/flow_controller.py +313 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/futures.py +83 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/__init__.py +19 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/__init__.py +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py +657 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/heartbeater.py +77 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/helper_threads.py +121 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/histogram.py +158 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/leaser.py +292 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/messages_on_hold.py +182 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/requests.py +64 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py +1423 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/client.py +323 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/exceptions.py +45 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/futures.py +124 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/message.py +563 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/scheduler.py +189 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/types.py +338 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/__init__.py +239 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/__pycache__/__init__.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/__pycache__/gapic_version.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/gapic_version.py +16 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/py.typed +2 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/__init__.py +319 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/__pycache__/__init__.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/__pycache__/gapic_version.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/gapic_metadata.json +922 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/gapic_version.py +16 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/py.typed +2 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/__init__.py +15 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/__pycache__/__init__.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__init__.py +22 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__pycache__/__init__.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__pycache__/async_client.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__pycache__/client.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__pycache__/pagers.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/async_client.py +1930 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/client.py +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/pagers.py +353 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__init__.py +36 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/__init__.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/base.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/grpc.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/grpc_asyncio.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/rest.cpython-312.pyc +3 -0
.gitattributes
CHANGED
|
@@ -422,3 +422,5 @@ loan-advisor-agent/.venv/Lib/site-packages/google/cloud/aiplatform_v1beta1/servi
|
|
| 422 |
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/__pycache__/rest_asyncio.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 423 |
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/__pycache__/rest_base.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 424 |
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/aiplatform_v1beta1/types/__pycache__/evaluation_service.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 422 |
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/__pycache__/rest_asyncio.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 423 |
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/__pycache__/rest_base.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 424 |
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/aiplatform_v1beta1/types/__pycache__/evaluation_service.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 425 |
+
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/rest.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 426 |
+
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/projects/transports/__pycache__/rest.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/_sequencer/ordered_sequencer.py
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import collections
|
| 16 |
+
import enum
|
| 17 |
+
import threading
|
| 18 |
+
import typing
|
| 19 |
+
from typing import Deque, Iterable, Sequence
|
| 20 |
+
|
| 21 |
+
from google.api_core import gapic_v1
|
| 22 |
+
|
| 23 |
+
from google.cloud.pubsub_v1.open_telemetry.publish_message_wrapper import (
|
| 24 |
+
PublishMessageWrapper,
|
| 25 |
+
)
|
| 26 |
+
from google.cloud.pubsub_v1.publisher import exceptions, futures
|
| 27 |
+
from google.cloud.pubsub_v1.publisher._batch import base as batch_base
|
| 28 |
+
from google.cloud.pubsub_v1.publisher._sequencer import base as sequencer_base
|
| 29 |
+
|
| 30 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 31 |
+
from google.cloud.pubsub_v1 import types
|
| 32 |
+
from google.cloud.pubsub_v1.publisher import _batch
|
| 33 |
+
from google.cloud.pubsub_v1.publisher.client import Client as PublisherClient
|
| 34 |
+
from google.pubsub_v1.services.publisher.client import OptionalRetry
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class _OrderedSequencerStatus(str, enum.Enum):
|
| 38 |
+
"""An enum-like class representing valid statuses for an OrderedSequencer.
|
| 39 |
+
|
| 40 |
+
Starting state: ACCEPTING_MESSAGES
|
| 41 |
+
Valid transitions:
|
| 42 |
+
ACCEPTING_MESSAGES -> PAUSED (on permanent error)
|
| 43 |
+
ACCEPTING_MESSAGES -> STOPPED (when user calls stop() explicitly)
|
| 44 |
+
ACCEPTING_MESSAGES -> FINISHED (all batch publishes finish normally)
|
| 45 |
+
|
| 46 |
+
PAUSED -> ACCEPTING_MESSAGES (when user unpauses)
|
| 47 |
+
PAUSED -> STOPPED (when user calls stop() explicitly)
|
| 48 |
+
|
| 49 |
+
STOPPED -> FINISHED (user stops client and the one remaining batch finishes
|
| 50 |
+
publish)
|
| 51 |
+
STOPPED -> PAUSED (stop() commits one batch, which fails permanently)
|
| 52 |
+
|
| 53 |
+
FINISHED -> ACCEPTING_MESSAGES (publish happens while waiting for cleanup)
|
| 54 |
+
FINISHED -> STOPPED (when user calls stop() explicitly)
|
| 55 |
+
Illegal transitions:
|
| 56 |
+
PAUSED -> FINISHED (since all batches are cancelled on pause, there should
|
| 57 |
+
not be any that finish normally. paused sequencers
|
| 58 |
+
should not be cleaned up because their presence
|
| 59 |
+
indicates that the ordering key needs to be resumed)
|
| 60 |
+
STOPPED -> ACCEPTING_MESSAGES (no way to make a user-stopped sequencer
|
| 61 |
+
accept messages again. this is okay since
|
| 62 |
+
stop() should only be called on shutdown.)
|
| 63 |
+
FINISHED -> PAUSED (no messages remain in flight, so they can't cause a
|
| 64 |
+
permanent error and pause the sequencer)
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
# Accepting publishes and/or waiting for result of batch publish
|
| 68 |
+
ACCEPTING_MESSAGES = "accepting messages"
|
| 69 |
+
# Permanent error occurred. User must unpause this sequencer to resume
|
| 70 |
+
# publishing. This is done to maintain ordering.
|
| 71 |
+
PAUSED = "paused"
|
| 72 |
+
# No more publishes allowed. There may be an outstanding batch that will
|
| 73 |
+
# call the _batch_done_callback when it's done (success or error.)
|
| 74 |
+
STOPPED = "stopped"
|
| 75 |
+
# No more work to do. Waiting to be cleaned-up. A publish will transform
|
| 76 |
+
# this sequencer back into the normal accepting-messages state.
|
| 77 |
+
FINISHED = "finished"
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class OrderedSequencer(sequencer_base.Sequencer):
|
| 81 |
+
"""Sequences messages into batches ordered by an ordering key for one topic.
|
| 82 |
+
|
| 83 |
+
A sequencer always has at least one batch in it, unless paused or stopped.
|
| 84 |
+
When no batches remain, the |publishes_done_callback| is called so the
|
| 85 |
+
client can perform cleanup.
|
| 86 |
+
|
| 87 |
+
Public methods are thread-safe.
|
| 88 |
+
|
| 89 |
+
Args:
|
| 90 |
+
client:
|
| 91 |
+
The publisher client used to create this sequencer.
|
| 92 |
+
topic:
|
| 93 |
+
The topic. The format for this is ``projects/{project}/topics/{topic}``.
|
| 94 |
+
ordering_key:
|
| 95 |
+
The ordering key for this sequencer.
|
| 96 |
+
"""
|
| 97 |
+
|
| 98 |
+
def __init__(self, client: "PublisherClient", topic: str, ordering_key: str):
|
| 99 |
+
self._client = client
|
| 100 |
+
self._topic = topic
|
| 101 |
+
self._ordering_key = ordering_key
|
| 102 |
+
# Guards the variables below
|
| 103 |
+
self._state_lock = threading.Lock()
|
| 104 |
+
# Batches ordered from first (head/left) to last (right/tail).
|
| 105 |
+
# Invariant: always has at least one batch after the first publish,
|
| 106 |
+
# unless paused or stopped.
|
| 107 |
+
self._ordered_batches: Deque["_batch.thread.Batch"] = collections.deque()
|
| 108 |
+
# See _OrderedSequencerStatus for valid state transitions.
|
| 109 |
+
self._state = _OrderedSequencerStatus.ACCEPTING_MESSAGES
|
| 110 |
+
|
| 111 |
+
def is_finished(self) -> bool:
|
| 112 |
+
"""Whether the sequencer is finished and should be cleaned up.
|
| 113 |
+
|
| 114 |
+
Returns:
|
| 115 |
+
Whether the sequencer is finished and should be cleaned up.
|
| 116 |
+
"""
|
| 117 |
+
with self._state_lock:
|
| 118 |
+
return self._state == _OrderedSequencerStatus.FINISHED
|
| 119 |
+
|
| 120 |
+
def stop(self) -> None:
|
| 121 |
+
"""Permanently stop this sequencer.
|
| 122 |
+
|
| 123 |
+
This differs from pausing, which may be resumed. Immediately commits
|
| 124 |
+
the first batch and cancels the rest.
|
| 125 |
+
|
| 126 |
+
Raises:
|
| 127 |
+
RuntimeError:
|
| 128 |
+
If called after stop() has already been called.
|
| 129 |
+
"""
|
| 130 |
+
with self._state_lock:
|
| 131 |
+
if self._state == _OrderedSequencerStatus.STOPPED:
|
| 132 |
+
raise RuntimeError("Ordered sequencer already stopped.")
|
| 133 |
+
|
| 134 |
+
self._state = _OrderedSequencerStatus.STOPPED
|
| 135 |
+
if self._ordered_batches:
|
| 136 |
+
# Give only the first batch the chance to finish.
|
| 137 |
+
self._ordered_batches[0].commit()
|
| 138 |
+
|
| 139 |
+
# Cancel the rest of the batches and remove them from the deque
|
| 140 |
+
# of batches.
|
| 141 |
+
while len(self._ordered_batches) > 1:
|
| 142 |
+
# Pops from the tail until it leaves only the head in the
|
| 143 |
+
# deque.
|
| 144 |
+
batch = self._ordered_batches.pop()
|
| 145 |
+
batch.cancel(batch_base.BatchCancellationReason.CLIENT_STOPPED)
|
| 146 |
+
|
| 147 |
+
def commit(self) -> None:
|
| 148 |
+
"""Commit the first batch, if unpaused.
|
| 149 |
+
|
| 150 |
+
If paused or no batches exist, this method does nothing.
|
| 151 |
+
|
| 152 |
+
Raises:
|
| 153 |
+
RuntimeError:
|
| 154 |
+
If called after stop() has already been called.
|
| 155 |
+
"""
|
| 156 |
+
with self._state_lock:
|
| 157 |
+
if self._state == _OrderedSequencerStatus.STOPPED:
|
| 158 |
+
raise RuntimeError("Ordered sequencer already stopped.")
|
| 159 |
+
|
| 160 |
+
if self._state != _OrderedSequencerStatus.PAUSED and self._ordered_batches:
|
| 161 |
+
# It's okay to commit the same batch more than once. The
|
| 162 |
+
# operation is idempotent.
|
| 163 |
+
self._ordered_batches[0].commit()
|
| 164 |
+
|
| 165 |
+
def _batch_done_callback(self, success: bool) -> None:
|
| 166 |
+
"""Deal with completion of a batch.
|
| 167 |
+
|
| 168 |
+
Called when a batch has finished publishing, with either a success
|
| 169 |
+
or a failure. (Temporary failures are retried infinitely when
|
| 170 |
+
ordering keys are enabled.)
|
| 171 |
+
"""
|
| 172 |
+
ensure_cleanup_and_commit_timer_runs = False
|
| 173 |
+
with self._state_lock:
|
| 174 |
+
assert self._state != _OrderedSequencerStatus.PAUSED, (
|
| 175 |
+
"This method should not be called after pause() because "
|
| 176 |
+
"pause() should have cancelled all of the batches."
|
| 177 |
+
)
|
| 178 |
+
assert self._state != _OrderedSequencerStatus.FINISHED, (
|
| 179 |
+
"This method should not be called after all batches have been finished."
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
# Message futures for the batch have been completed (either with a
|
| 183 |
+
# result or an exception) already, so remove the batch.
|
| 184 |
+
self._ordered_batches.popleft()
|
| 185 |
+
|
| 186 |
+
if success:
|
| 187 |
+
if len(self._ordered_batches) == 0:
|
| 188 |
+
# Mark this sequencer as finished.
|
| 189 |
+
# If new messages come in for this ordering key and this
|
| 190 |
+
# sequencer hasn't been cleaned up yet, it will go back
|
| 191 |
+
# into accepting-messages state. Otherwise, the client
|
| 192 |
+
# must create a new OrderedSequencer.
|
| 193 |
+
self._state = _OrderedSequencerStatus.FINISHED
|
| 194 |
+
# Ensure cleanup thread runs at some point.
|
| 195 |
+
ensure_cleanup_and_commit_timer_runs = True
|
| 196 |
+
elif len(self._ordered_batches) == 1:
|
| 197 |
+
# Wait for messages and/or commit timeout
|
| 198 |
+
# Ensure there's actually a commit timer thread that'll commit
|
| 199 |
+
# after a delay.
|
| 200 |
+
ensure_cleanup_and_commit_timer_runs = True
|
| 201 |
+
else:
|
| 202 |
+
# If there is more than one batch, we know that the next batch
|
| 203 |
+
# must be full and, therefore, ready to be committed.
|
| 204 |
+
self._ordered_batches[0].commit()
|
| 205 |
+
else:
|
| 206 |
+
# Unrecoverable error detected
|
| 207 |
+
self._pause()
|
| 208 |
+
|
| 209 |
+
if ensure_cleanup_and_commit_timer_runs:
|
| 210 |
+
self._client.ensure_cleanup_and_commit_timer_runs()
|
| 211 |
+
|
| 212 |
+
def _pause(self) -> None:
|
| 213 |
+
"""Pause this sequencer: set state to paused, cancel all batches, and
|
| 214 |
+
clear the list of ordered batches.
|
| 215 |
+
|
| 216 |
+
_state_lock must be taken before calling this method.
|
| 217 |
+
"""
|
| 218 |
+
assert self._state != _OrderedSequencerStatus.FINISHED, (
|
| 219 |
+
"Pause should not be called after all batches have finished."
|
| 220 |
+
)
|
| 221 |
+
self._state = _OrderedSequencerStatus.PAUSED
|
| 222 |
+
for batch in self._ordered_batches:
|
| 223 |
+
batch.cancel(
|
| 224 |
+
batch_base.BatchCancellationReason.PRIOR_ORDERED_MESSAGE_FAILED
|
| 225 |
+
)
|
| 226 |
+
self._ordered_batches.clear()
|
| 227 |
+
|
| 228 |
+
def unpause(self) -> None:
|
| 229 |
+
"""Unpause this sequencer.
|
| 230 |
+
|
| 231 |
+
Raises:
|
| 232 |
+
RuntimeError:
|
| 233 |
+
If called when the ordering key has not been paused.
|
| 234 |
+
"""
|
| 235 |
+
with self._state_lock:
|
| 236 |
+
if self._state != _OrderedSequencerStatus.PAUSED:
|
| 237 |
+
raise RuntimeError("Ordering key is not paused.")
|
| 238 |
+
self._state = _OrderedSequencerStatus.ACCEPTING_MESSAGES
|
| 239 |
+
|
| 240 |
+
def _create_batch(
|
| 241 |
+
self,
|
| 242 |
+
commit_retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
|
| 243 |
+
commit_timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
|
| 244 |
+
) -> "_batch.thread.Batch":
|
| 245 |
+
"""Create a new batch using the client's batch class and other stored
|
| 246 |
+
settings.
|
| 247 |
+
|
| 248 |
+
Args:
|
| 249 |
+
commit_retry:
|
| 250 |
+
The retry settings to apply when publishing the batch.
|
| 251 |
+
commit_timeout:
|
| 252 |
+
The timeout to apply when publishing the batch.
|
| 253 |
+
"""
|
| 254 |
+
return self._client._batch_class(
|
| 255 |
+
client=self._client,
|
| 256 |
+
topic=self._topic,
|
| 257 |
+
settings=self._client.batch_settings,
|
| 258 |
+
batch_done_callback=self._batch_done_callback,
|
| 259 |
+
commit_when_full=False,
|
| 260 |
+
commit_retry=commit_retry,
|
| 261 |
+
commit_timeout=commit_timeout,
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
def publish(
|
| 265 |
+
self,
|
| 266 |
+
wrapper: PublishMessageWrapper,
|
| 267 |
+
retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
|
| 268 |
+
timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
|
| 269 |
+
) -> futures.Future:
|
| 270 |
+
"""Publish message for this ordering key.
|
| 271 |
+
|
| 272 |
+
Args:
|
| 273 |
+
wrapper:
|
| 274 |
+
The Pub/Sub message wrapper.
|
| 275 |
+
retry:
|
| 276 |
+
The retry settings to apply when publishing the message.
|
| 277 |
+
timeout:
|
| 278 |
+
The timeout to apply when publishing the message.
|
| 279 |
+
|
| 280 |
+
Returns:
|
| 281 |
+
A class instance that conforms to Python Standard library's
|
| 282 |
+
:class:`~concurrent.futures.Future` interface (but not an
|
| 283 |
+
instance of that class). The future might return immediately with a
|
| 284 |
+
PublishToPausedOrderingKeyException if the ordering key is paused.
|
| 285 |
+
Otherwise, the future tracks the lifetime of the message publish.
|
| 286 |
+
|
| 287 |
+
Raises:
|
| 288 |
+
RuntimeError:
|
| 289 |
+
If called after this sequencer has been stopped, either by
|
| 290 |
+
a call to stop() or after all batches have been published.
|
| 291 |
+
"""
|
| 292 |
+
with self._state_lock:
|
| 293 |
+
if self._state == _OrderedSequencerStatus.PAUSED:
|
| 294 |
+
errored_future = futures.Future()
|
| 295 |
+
exception = exceptions.PublishToPausedOrderingKeyException(
|
| 296 |
+
self._ordering_key
|
| 297 |
+
)
|
| 298 |
+
errored_future.set_exception(exception)
|
| 299 |
+
return errored_future
|
| 300 |
+
|
| 301 |
+
# If waiting to be cleaned-up, convert to accepting messages to
|
| 302 |
+
# prevent this sequencer from being cleaned-up only to have another
|
| 303 |
+
# one with the same ordering key created immediately afterward.
|
| 304 |
+
if self._state == _OrderedSequencerStatus.FINISHED:
|
| 305 |
+
self._state = _OrderedSequencerStatus.ACCEPTING_MESSAGES
|
| 306 |
+
|
| 307 |
+
if self._state == _OrderedSequencerStatus.STOPPED:
|
| 308 |
+
raise RuntimeError("Cannot publish on a stopped sequencer.")
|
| 309 |
+
|
| 310 |
+
assert self._state == _OrderedSequencerStatus.ACCEPTING_MESSAGES, (
|
| 311 |
+
"Publish is only allowed in accepting-messages state."
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
if not self._ordered_batches:
|
| 315 |
+
new_batch = self._create_batch(
|
| 316 |
+
commit_retry=retry, commit_timeout=timeout
|
| 317 |
+
)
|
| 318 |
+
self._ordered_batches.append(new_batch)
|
| 319 |
+
|
| 320 |
+
batch = self._ordered_batches[-1]
|
| 321 |
+
future = batch.publish(wrapper)
|
| 322 |
+
while future is None:
|
| 323 |
+
batch = self._create_batch(commit_retry=retry, commit_timeout=timeout)
|
| 324 |
+
self._ordered_batches.append(batch)
|
| 325 |
+
future = batch.publish(wrapper)
|
| 326 |
+
|
| 327 |
+
return future
|
| 328 |
+
|
| 329 |
+
# Used only for testing.
|
| 330 |
+
def _set_batch(self, batch: "_batch.thread.Batch") -> None:
|
| 331 |
+
self._ordered_batches = collections.deque([batch])
|
| 332 |
+
|
| 333 |
+
# Used only for testing.
|
| 334 |
+
def _set_batches(self, batches: Iterable["_batch.thread.Batch"]) -> None:
|
| 335 |
+
self._ordered_batches = collections.deque(batches)
|
| 336 |
+
|
| 337 |
+
# Used only for testing.
|
| 338 |
+
def _get_batches(self) -> Sequence["_batch.thread.Batch"]:
|
| 339 |
+
return self._ordered_batches
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/_sequencer/unordered_sequencer.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import typing
|
| 16 |
+
from typing import Optional
|
| 17 |
+
|
| 18 |
+
from google.api_core import gapic_v1
|
| 19 |
+
|
| 20 |
+
from google.cloud.pubsub_v1.open_telemetry.publish_message_wrapper import (
|
| 21 |
+
PublishMessageWrapper,
|
| 22 |
+
)
|
| 23 |
+
from google.cloud.pubsub_v1.publisher._sequencer import base
|
| 24 |
+
|
| 25 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 26 |
+
from google.cloud.pubsub_v1 import types
|
| 27 |
+
from google.cloud.pubsub_v1.publisher import _batch, futures
|
| 28 |
+
from google.cloud.pubsub_v1.publisher.client import Client as PublisherClient
|
| 29 |
+
from google.pubsub_v1.services.publisher.client import OptionalRetry
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class UnorderedSequencer(base.Sequencer):
|
| 33 |
+
"""Sequences messages into batches for one topic without any ordering.
|
| 34 |
+
|
| 35 |
+
Public methods are NOT thread-safe.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
def __init__(self, client: "PublisherClient", topic: str):
|
| 39 |
+
self._client = client
|
| 40 |
+
self._topic = topic
|
| 41 |
+
self._current_batch: Optional["_batch.thread.Batch"] = None
|
| 42 |
+
self._stopped = False
|
| 43 |
+
|
| 44 |
+
def is_finished(self) -> bool:
|
| 45 |
+
"""Whether the sequencer is finished and should be cleaned up.
|
| 46 |
+
|
| 47 |
+
Returns:
|
| 48 |
+
Whether the sequencer is finished and should be cleaned up.
|
| 49 |
+
"""
|
| 50 |
+
# TODO: Implement. Not implementing yet because of possible performance
|
| 51 |
+
# impact due to extra locking required. This does mean that
|
| 52 |
+
# UnorderedSequencers don't get cleaned up, but this is the same as
|
| 53 |
+
# previously existing behavior.
|
| 54 |
+
return False
|
| 55 |
+
|
| 56 |
+
def stop(self) -> None:
|
| 57 |
+
"""Stop the sequencer.
|
| 58 |
+
|
| 59 |
+
Subsequent publishes will fail.
|
| 60 |
+
|
| 61 |
+
Raises:
|
| 62 |
+
RuntimeError:
|
| 63 |
+
If called after stop() has already been called.
|
| 64 |
+
"""
|
| 65 |
+
if self._stopped:
|
| 66 |
+
raise RuntimeError("Unordered sequencer already stopped.")
|
| 67 |
+
self.commit()
|
| 68 |
+
self._stopped = True
|
| 69 |
+
|
| 70 |
+
def commit(self) -> None:
|
| 71 |
+
"""Commit the batch.
|
| 72 |
+
|
| 73 |
+
Raises:
|
| 74 |
+
RuntimeError:
|
| 75 |
+
If called after stop() has already been called.
|
| 76 |
+
"""
|
| 77 |
+
if self._stopped:
|
| 78 |
+
raise RuntimeError("Unordered sequencer already stopped.")
|
| 79 |
+
if self._current_batch:
|
| 80 |
+
self._current_batch.commit()
|
| 81 |
+
|
| 82 |
+
# At this point, we lose track of the old batch, but we don't
|
| 83 |
+
# care since we just committed it.
|
| 84 |
+
# Setting this to None guarantees the next publish() creates a new
|
| 85 |
+
# batch.
|
| 86 |
+
self._current_batch = None
|
| 87 |
+
|
| 88 |
+
def unpause(self) -> typing.NoReturn:
|
| 89 |
+
"""Not relevant for this class."""
|
| 90 |
+
raise NotImplementedError
|
| 91 |
+
|
| 92 |
+
def _create_batch(
|
| 93 |
+
self,
|
| 94 |
+
commit_retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
|
| 95 |
+
commit_timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
|
| 96 |
+
) -> "_batch.thread.Batch":
|
| 97 |
+
"""Create a new batch using the client's batch class and other stored
|
| 98 |
+
settings.
|
| 99 |
+
|
| 100 |
+
Args:
|
| 101 |
+
commit_retry:
|
| 102 |
+
The retry settings to apply when publishing the batch.
|
| 103 |
+
commit_timeout:
|
| 104 |
+
The timeout to apply when publishing the batch.
|
| 105 |
+
"""
|
| 106 |
+
return self._client._batch_class(
|
| 107 |
+
client=self._client,
|
| 108 |
+
topic=self._topic,
|
| 109 |
+
settings=self._client.batch_settings,
|
| 110 |
+
batch_done_callback=None,
|
| 111 |
+
commit_when_full=True,
|
| 112 |
+
commit_retry=commit_retry,
|
| 113 |
+
commit_timeout=commit_timeout,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
def publish(
|
| 117 |
+
self,
|
| 118 |
+
wrapper: PublishMessageWrapper,
|
| 119 |
+
retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
|
| 120 |
+
timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
|
| 121 |
+
) -> "futures.Future":
|
| 122 |
+
"""Batch message into existing or new batch.
|
| 123 |
+
|
| 124 |
+
Args:
|
| 125 |
+
wrapper:
|
| 126 |
+
The Pub/Sub message wrapper.
|
| 127 |
+
retry:
|
| 128 |
+
The retry settings to apply when publishing the message.
|
| 129 |
+
timeout:
|
| 130 |
+
The timeout to apply when publishing the message.
|
| 131 |
+
|
| 132 |
+
Returns:
|
| 133 |
+
An object conforming to the :class:`~concurrent.futures.Future` interface.
|
| 134 |
+
The future tracks the publishing status of the message.
|
| 135 |
+
|
| 136 |
+
Raises:
|
| 137 |
+
RuntimeError:
|
| 138 |
+
If called after stop() has already been called.
|
| 139 |
+
|
| 140 |
+
pubsub_v1.publisher.exceptions.MessageTooLargeError: If publishing
|
| 141 |
+
the ``message`` would exceed the max size limit on the backend.
|
| 142 |
+
"""
|
| 143 |
+
if self._stopped:
|
| 144 |
+
raise RuntimeError("Unordered sequencer already stopped.")
|
| 145 |
+
|
| 146 |
+
if not self._current_batch:
|
| 147 |
+
newbatch = self._create_batch(commit_retry=retry, commit_timeout=timeout)
|
| 148 |
+
self._current_batch = newbatch
|
| 149 |
+
|
| 150 |
+
batch = self._current_batch
|
| 151 |
+
future = None
|
| 152 |
+
while future is None:
|
| 153 |
+
# Might throw MessageTooLargeError
|
| 154 |
+
future = batch.publish(wrapper)
|
| 155 |
+
# batch is full, triggering commit_when_full
|
| 156 |
+
if future is None:
|
| 157 |
+
batch = self._create_batch(commit_retry=retry, commit_timeout=timeout)
|
| 158 |
+
# At this point, we lose track of the old batch, but we don't
|
| 159 |
+
# care since it's already committed (because it was full.)
|
| 160 |
+
self._current_batch = batch
|
| 161 |
+
return future
|
| 162 |
+
|
| 163 |
+
# Used only for testing.
|
| 164 |
+
def _set_batch(self, batch: "_batch.thread.Batch") -> None:
|
| 165 |
+
self._current_batch = batch
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/client.py
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
import copy
|
| 18 |
+
import logging
|
| 19 |
+
import os
|
| 20 |
+
import sys
|
| 21 |
+
import threading
|
| 22 |
+
import time
|
| 23 |
+
import typing
|
| 24 |
+
import warnings
|
| 25 |
+
from typing import Any, Dict, Optional, Sequence, Tuple, Type, Union
|
| 26 |
+
|
| 27 |
+
from google.api_core import gapic_v1
|
| 28 |
+
from google.auth.credentials import AnonymousCredentials # type: ignore
|
| 29 |
+
from google.oauth2 import service_account # type: ignore
|
| 30 |
+
|
| 31 |
+
from google.cloud.pubsub_v1 import types
|
| 32 |
+
from google.cloud.pubsub_v1.open_telemetry.publish_message_wrapper import (
|
| 33 |
+
PublishMessageWrapper,
|
| 34 |
+
)
|
| 35 |
+
from google.cloud.pubsub_v1.publisher import exceptions, futures
|
| 36 |
+
from google.cloud.pubsub_v1.publisher._batch import thread
|
| 37 |
+
from google.cloud.pubsub_v1.publisher._sequencer import (
|
| 38 |
+
ordered_sequencer,
|
| 39 |
+
unordered_sequencer,
|
| 40 |
+
)
|
| 41 |
+
from google.cloud.pubsub_v1.publisher.flow_controller import FlowController
|
| 42 |
+
from google.pubsub_v1 import gapic_version as package_version
|
| 43 |
+
from google.pubsub_v1 import types as gapic_types
|
| 44 |
+
from google.pubsub_v1.services.publisher import client as publisher_client
|
| 45 |
+
|
| 46 |
+
__version__ = package_version.__version__
|
| 47 |
+
|
| 48 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 49 |
+
from google.cloud import pubsub_v1
|
| 50 |
+
from google.cloud.pubsub_v1.publisher import _batch
|
| 51 |
+
from google.pubsub_v1.services.publisher.client import OptionalRetry
|
| 52 |
+
from google.pubsub_v1.types import pubsub as pubsub_types
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
_LOGGER = logging.getLogger(__name__)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
_raw_proto_pubbsub_message = gapic_types.PubsubMessage.pb()
|
| 59 |
+
|
| 60 |
+
SequencerType = Union[
|
| 61 |
+
ordered_sequencer.OrderedSequencer, unordered_sequencer.UnorderedSequencer
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class Client(publisher_client.PublisherClient):
|
| 66 |
+
"""A publisher client for Google Cloud Pub/Sub.
|
| 67 |
+
|
| 68 |
+
This creates an object that is capable of publishing messages.
|
| 69 |
+
Generally, you can instantiate this client with no arguments, and you
|
| 70 |
+
get sensible defaults.
|
| 71 |
+
|
| 72 |
+
Args:
|
| 73 |
+
batch_settings:
|
| 74 |
+
The settings for batch publishing.
|
| 75 |
+
publisher_options:
|
| 76 |
+
The options for the publisher client. Note that enabling message ordering
|
| 77 |
+
will override the publish retry timeout to be infinite.
|
| 78 |
+
kwargs:
|
| 79 |
+
Any additional arguments provided are sent as keyword arguments to the
|
| 80 |
+
underlying
|
| 81 |
+
:class:`~google.cloud.pubsub_v1.gapic.publisher_client.PublisherClient`.
|
| 82 |
+
Generally you should not need to set additional keyword
|
| 83 |
+
arguments. Regional endpoints can be set via ``client_options`` that
|
| 84 |
+
takes a single key-value pair that defines the endpoint.
|
| 85 |
+
|
| 86 |
+
Example:
|
| 87 |
+
|
| 88 |
+
.. code-block:: python
|
| 89 |
+
|
| 90 |
+
from google.cloud import pubsub_v1
|
| 91 |
+
|
| 92 |
+
publisher_client = pubsub_v1.PublisherClient(
|
| 93 |
+
# Optional
|
| 94 |
+
batch_settings = pubsub_v1.types.BatchSettings(
|
| 95 |
+
max_bytes=1024, # One kilobyte
|
| 96 |
+
max_latency=1, # One second
|
| 97 |
+
),
|
| 98 |
+
|
| 99 |
+
# Optional
|
| 100 |
+
publisher_options = pubsub_v1.types.PublisherOptions(
|
| 101 |
+
enable_message_ordering=False,
|
| 102 |
+
flow_control=pubsub_v1.types.PublishFlowControl(
|
| 103 |
+
message_limit=2000,
|
| 104 |
+
limit_exceeded_behavior=pubsub_v1.types.LimitExceededBehavior.BLOCK,
|
| 105 |
+
),
|
| 106 |
+
),
|
| 107 |
+
|
| 108 |
+
# Optional
|
| 109 |
+
client_options = {
|
| 110 |
+
"api_endpoint": REGIONAL_ENDPOINT
|
| 111 |
+
}
|
| 112 |
+
)
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
def __init__(
|
| 116 |
+
self,
|
| 117 |
+
batch_settings: Union[types.BatchSettings, Sequence] = (),
|
| 118 |
+
publisher_options: Union[types.PublisherOptions, Sequence] = (),
|
| 119 |
+
**kwargs: Any,
|
| 120 |
+
):
|
| 121 |
+
assert (
|
| 122 |
+
type(batch_settings) is types.BatchSettings or len(batch_settings) == 0
|
| 123 |
+
), "batch_settings must be of type BatchSettings or an empty sequence."
|
| 124 |
+
assert (
|
| 125 |
+
type(publisher_options) is types.PublisherOptions
|
| 126 |
+
or len(publisher_options) == 0
|
| 127 |
+
), "publisher_options must be of type PublisherOptions or an empty sequence."
|
| 128 |
+
|
| 129 |
+
# Sanity check: Is our goal to use the emulator?
|
| 130 |
+
# If so, create a grpc insecure channel with the emulator host
|
| 131 |
+
# as the target.
|
| 132 |
+
# TODO(https://github.com/googleapis/python-pubsub/issues/1349): Move the emulator
|
| 133 |
+
# code below to test files.
|
| 134 |
+
if os.environ.get("PUBSUB_EMULATOR_HOST"):
|
| 135 |
+
kwargs["client_options"] = {
|
| 136 |
+
"api_endpoint": os.environ.get("PUBSUB_EMULATOR_HOST")
|
| 137 |
+
}
|
| 138 |
+
# Configure credentials directly to transport, if provided.
|
| 139 |
+
if "transport" not in kwargs:
|
| 140 |
+
kwargs["credentials"] = AnonymousCredentials()
|
| 141 |
+
|
| 142 |
+
# For a transient failure, retry publishing the message infinitely.
|
| 143 |
+
self.publisher_options = types.PublisherOptions(*publisher_options)
|
| 144 |
+
self._enable_message_ordering = self.publisher_options[0]
|
| 145 |
+
|
| 146 |
+
# Add the metrics headers, and instantiate the underlying GAPIC
|
| 147 |
+
# client.
|
| 148 |
+
super().__init__(**kwargs)
|
| 149 |
+
self._target = self._transport._host
|
| 150 |
+
self._batch_class = thread.Batch
|
| 151 |
+
self.batch_settings = types.BatchSettings(*batch_settings)
|
| 152 |
+
|
| 153 |
+
# The batches on the publisher client are responsible for holding
|
| 154 |
+
# messages. One batch exists for each topic.
|
| 155 |
+
self._batch_lock = self._batch_class.make_lock()
|
| 156 |
+
# (topic, ordering_key) => sequencers object
|
| 157 |
+
self._sequencers: Dict[Tuple[str, str], SequencerType] = {}
|
| 158 |
+
self._is_stopped = False
|
| 159 |
+
# Thread created to commit all sequencers after a timeout.
|
| 160 |
+
self._commit_thread: Optional[threading.Thread] = None
|
| 161 |
+
|
| 162 |
+
# The object controlling the message publishing flow
|
| 163 |
+
self._flow_controller = FlowController(self.publisher_options.flow_control)
|
| 164 |
+
|
| 165 |
+
self._open_telemetry_enabled = (
|
| 166 |
+
self.publisher_options.enable_open_telemetry_tracing
|
| 167 |
+
)
|
| 168 |
+
# OpenTelemetry features used by the library are not supported in Python versions <= 3.7.
|
| 169 |
+
# Refer https://github.com/open-telemetry/opentelemetry-python/issues/3993#issuecomment-2211976389
|
| 170 |
+
if (
|
| 171 |
+
self.publisher_options.enable_open_telemetry_tracing
|
| 172 |
+
and sys.version_info.major == 3
|
| 173 |
+
and sys.version_info.minor < 8
|
| 174 |
+
):
|
| 175 |
+
warnings.warn(
|
| 176 |
+
message="Open Telemetry for Python version 3.7 or lower is not supported. Disabling Open Telemetry tracing.",
|
| 177 |
+
category=RuntimeWarning,
|
| 178 |
+
)
|
| 179 |
+
self._open_telemetry_enabled = False
|
| 180 |
+
|
| 181 |
+
@classmethod
|
| 182 |
+
def from_service_account_file( # type: ignore[override]
|
| 183 |
+
cls,
|
| 184 |
+
filename: str,
|
| 185 |
+
batch_settings: Union[types.BatchSettings, Sequence] = (),
|
| 186 |
+
**kwargs: Any,
|
| 187 |
+
) -> "Client":
|
| 188 |
+
"""Creates an instance of this client using the provided credentials
|
| 189 |
+
file.
|
| 190 |
+
|
| 191 |
+
Args:
|
| 192 |
+
filename:
|
| 193 |
+
The path to the service account private key JSON file.
|
| 194 |
+
batch_settings:
|
| 195 |
+
The settings for batch publishing.
|
| 196 |
+
kwargs:
|
| 197 |
+
Additional arguments to pass to the constructor.
|
| 198 |
+
|
| 199 |
+
Returns:
|
| 200 |
+
A Publisher instance that is the constructed client.
|
| 201 |
+
"""
|
| 202 |
+
credentials = service_account.Credentials.from_service_account_file(filename)
|
| 203 |
+
kwargs["credentials"] = credentials
|
| 204 |
+
return cls(batch_settings, **kwargs)
|
| 205 |
+
|
| 206 |
+
from_service_account_json = from_service_account_file # type: ignore[assignment]
|
| 207 |
+
|
| 208 |
+
@property
|
| 209 |
+
def target(self) -> str:
|
| 210 |
+
"""Return the target (where the API is).
|
| 211 |
+
|
| 212 |
+
Returns:
|
| 213 |
+
The location of the API.
|
| 214 |
+
"""
|
| 215 |
+
return self._target
|
| 216 |
+
|
| 217 |
+
@property
|
| 218 |
+
def api(self):
|
| 219 |
+
"""The underlying gapic API client.
|
| 220 |
+
|
| 221 |
+
.. versionchanged:: 2.10.0
|
| 222 |
+
Instead of a GAPIC ``PublisherClient`` client instance, this property is a
|
| 223 |
+
proxy object to it with the same interface.
|
| 224 |
+
|
| 225 |
+
.. deprecated:: 2.10.0
|
| 226 |
+
Use the GAPIC methods and properties on the client instance directly
|
| 227 |
+
instead of through the :attr:`api` attribute.
|
| 228 |
+
"""
|
| 229 |
+
msg = (
|
| 230 |
+
'The "api" property only exists for backward compatibility, access its '
|
| 231 |
+
'attributes directly thorugh the client instance (e.g. "client.foo" '
|
| 232 |
+
'instead of "client.api.foo").'
|
| 233 |
+
)
|
| 234 |
+
warnings.warn(msg, category=DeprecationWarning)
|
| 235 |
+
return super()
|
| 236 |
+
|
| 237 |
+
@property
|
| 238 |
+
def open_telemetry_enabled(self) -> bool:
|
| 239 |
+
return self._open_telemetry_enabled
|
| 240 |
+
|
| 241 |
+
def _get_or_create_sequencer(self, topic: str, ordering_key: str) -> SequencerType:
|
| 242 |
+
"""Get an existing sequencer or create a new one given the (topic,
|
| 243 |
+
ordering_key) pair.
|
| 244 |
+
"""
|
| 245 |
+
sequencer_key = (topic, ordering_key)
|
| 246 |
+
sequencer = self._sequencers.get(sequencer_key)
|
| 247 |
+
if sequencer is None:
|
| 248 |
+
if ordering_key == "":
|
| 249 |
+
sequencer = unordered_sequencer.UnorderedSequencer(self, topic)
|
| 250 |
+
else:
|
| 251 |
+
sequencer = ordered_sequencer.OrderedSequencer(
|
| 252 |
+
self, topic, ordering_key
|
| 253 |
+
)
|
| 254 |
+
self._sequencers[sequencer_key] = sequencer
|
| 255 |
+
|
| 256 |
+
return sequencer
|
| 257 |
+
|
| 258 |
+
def resume_publish(self, topic: str, ordering_key: str) -> None:
|
| 259 |
+
"""Resume publish on an ordering key that has had unrecoverable errors.
|
| 260 |
+
|
| 261 |
+
Args:
|
| 262 |
+
topic: The topic to publish messages to.
|
| 263 |
+
ordering_key: A string that identifies related messages for which
|
| 264 |
+
publish order should be respected.
|
| 265 |
+
|
| 266 |
+
Raises:
|
| 267 |
+
RuntimeError:
|
| 268 |
+
If called after publisher has been stopped by a `stop()` method
|
| 269 |
+
call.
|
| 270 |
+
ValueError:
|
| 271 |
+
If the topic/ordering key combination has not been seen before
|
| 272 |
+
by this client.
|
| 273 |
+
"""
|
| 274 |
+
with self._batch_lock:
|
| 275 |
+
if self._is_stopped:
|
| 276 |
+
raise RuntimeError("Cannot resume publish on a stopped publisher.")
|
| 277 |
+
|
| 278 |
+
if not self._enable_message_ordering:
|
| 279 |
+
raise ValueError(
|
| 280 |
+
"Cannot resume publish on a topic/ordering key if ordering "
|
| 281 |
+
"is not enabled."
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
sequencer_key = (topic, ordering_key)
|
| 285 |
+
sequencer = self._sequencers.get(sequencer_key)
|
| 286 |
+
if sequencer is None:
|
| 287 |
+
_LOGGER.debug(
|
| 288 |
+
"Error: The topic/ordering key combination has not "
|
| 289 |
+
"been seen before."
|
| 290 |
+
)
|
| 291 |
+
else:
|
| 292 |
+
sequencer.unpause()
|
| 293 |
+
|
| 294 |
+
def _gapic_publish(self, *args, **kwargs) -> "pubsub_types.PublishResponse":
|
| 295 |
+
"""Call the GAPIC public API directly."""
|
| 296 |
+
return super().publish(*args, **kwargs)
|
| 297 |
+
|
| 298 |
+
def publish( # type: ignore[override]
|
| 299 |
+
self,
|
| 300 |
+
topic: str,
|
| 301 |
+
data: bytes,
|
| 302 |
+
ordering_key: str = "",
|
| 303 |
+
retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
|
| 304 |
+
timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
|
| 305 |
+
**attrs: Union[bytes, str],
|
| 306 |
+
) -> "pubsub_v1.publisher.futures.Future":
|
| 307 |
+
"""Publish a single message.
|
| 308 |
+
|
| 309 |
+
.. note::
|
| 310 |
+
Messages in Pub/Sub are blobs of bytes. They are *binary* data,
|
| 311 |
+
not text. You must send data as a bytestring
|
| 312 |
+
(``bytes`` in Python 3; ``str`` in Python 2), and this library
|
| 313 |
+
will raise an exception if you send a text string.
|
| 314 |
+
|
| 315 |
+
The reason that this is so important (and why we do not try to
|
| 316 |
+
coerce for you) is because Pub/Sub is also platform independent
|
| 317 |
+
and there is no way to know how to decode messages properly on
|
| 318 |
+
the other side; therefore, encoding and decoding is a required
|
| 319 |
+
exercise for the developer.
|
| 320 |
+
|
| 321 |
+
Add the given message to this object; this will cause it to be
|
| 322 |
+
published once the batch either has enough messages or a sufficient
|
| 323 |
+
period of time has elapsed.
|
| 324 |
+
This method may block if LimitExceededBehavior.BLOCK is used in the
|
| 325 |
+
flow control settings.
|
| 326 |
+
|
| 327 |
+
Example:
|
| 328 |
+
>>> from google.cloud import pubsub_v1
|
| 329 |
+
>>> client = pubsub_v1.PublisherClient()
|
| 330 |
+
>>> topic = client.topic_path('[PROJECT]', '[TOPIC]')
|
| 331 |
+
>>> data = b'The rain in Wales falls mainly on the snails.'
|
| 332 |
+
>>> response = client.publish(topic, data, username='guido')
|
| 333 |
+
|
| 334 |
+
Args:
|
| 335 |
+
topic: The topic to publish messages to.
|
| 336 |
+
data: A bytestring representing the message body. This
|
| 337 |
+
must be a bytestring.
|
| 338 |
+
ordering_key: A string that identifies related messages for which
|
| 339 |
+
publish order should be respected. Message ordering must be
|
| 340 |
+
enabled for this client to use this feature.
|
| 341 |
+
retry:
|
| 342 |
+
Designation of what errors, if any, should be retried. If `ordering_key`
|
| 343 |
+
is specified, the total retry deadline will be changed to "infinity".
|
| 344 |
+
If given, it overides any retry passed into the client through
|
| 345 |
+
the ``publisher_options`` argument.
|
| 346 |
+
timeout:
|
| 347 |
+
The timeout for the RPC request. Can be used to override any timeout
|
| 348 |
+
passed in through ``publisher_options`` when instantiating the client.
|
| 349 |
+
|
| 350 |
+
attrs: A dictionary of attributes to be
|
| 351 |
+
sent as metadata. (These may be text strings or byte strings.)
|
| 352 |
+
|
| 353 |
+
Returns:
|
| 354 |
+
A :class:`~google.cloud.pubsub_v1.publisher.futures.Future`
|
| 355 |
+
instance that conforms to Python Standard library's
|
| 356 |
+
:class:`~concurrent.futures.Future` interface (but not an
|
| 357 |
+
instance of that class).
|
| 358 |
+
|
| 359 |
+
Raises:
|
| 360 |
+
RuntimeError:
|
| 361 |
+
If called after publisher has been stopped by a `stop()` method
|
| 362 |
+
call.
|
| 363 |
+
|
| 364 |
+
pubsub_v1.publisher.exceptions.MessageTooLargeError: If publishing
|
| 365 |
+
the ``message`` would exceed the max size limit on the backend.
|
| 366 |
+
"""
|
| 367 |
+
# Sanity check: Is the data being sent as a bytestring?
|
| 368 |
+
# If it is literally anything else, complain loudly about it.
|
| 369 |
+
if not isinstance(data, bytes):
|
| 370 |
+
raise TypeError(
|
| 371 |
+
"Data being published to Pub/Sub must be sent as a bytestring."
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
+
if not self._enable_message_ordering and ordering_key != "":
|
| 375 |
+
raise ValueError(
|
| 376 |
+
"Cannot publish a message with an ordering key when message "
|
| 377 |
+
"ordering is not enabled."
|
| 378 |
+
)
|
| 379 |
+
|
| 380 |
+
# Coerce all attributes to text strings.
|
| 381 |
+
for k, v in copy.copy(attrs).items():
|
| 382 |
+
if isinstance(v, str):
|
| 383 |
+
continue
|
| 384 |
+
if isinstance(v, bytes):
|
| 385 |
+
attrs[k] = v.decode("utf-8")
|
| 386 |
+
continue
|
| 387 |
+
raise TypeError(
|
| 388 |
+
"All attributes being published to Pub/Sub must "
|
| 389 |
+
"be sent as text strings."
|
| 390 |
+
)
|
| 391 |
+
|
| 392 |
+
# Create the Pub/Sub message object. For performance reasons, the message
|
| 393 |
+
# should be constructed by directly using the raw protobuf class, and only
|
| 394 |
+
# then wrapping it into the higher-level PubsubMessage class.
|
| 395 |
+
vanilla_pb = _raw_proto_pubbsub_message(
|
| 396 |
+
data=data, ordering_key=ordering_key, attributes=attrs
|
| 397 |
+
)
|
| 398 |
+
message = gapic_types.PubsubMessage.wrap(vanilla_pb)
|
| 399 |
+
|
| 400 |
+
wrapper: PublishMessageWrapper = PublishMessageWrapper(message)
|
| 401 |
+
if self._open_telemetry_enabled:
|
| 402 |
+
wrapper.start_create_span(topic=topic, ordering_key=ordering_key)
|
| 403 |
+
|
| 404 |
+
# Messages should go through flow control to prevent excessive
|
| 405 |
+
# queuing on the client side (depending on the settings).
|
| 406 |
+
try:
|
| 407 |
+
if self._open_telemetry_enabled:
|
| 408 |
+
if wrapper:
|
| 409 |
+
wrapper.start_publisher_flow_control_span()
|
| 410 |
+
else: # pragma: NO COVER
|
| 411 |
+
warnings.warn(
|
| 412 |
+
message="PubSubMessageWrapper is None. Not starting publisher flow control span.",
|
| 413 |
+
category=RuntimeWarning,
|
| 414 |
+
)
|
| 415 |
+
self._flow_controller.add(message)
|
| 416 |
+
if self._open_telemetry_enabled:
|
| 417 |
+
if wrapper:
|
| 418 |
+
wrapper.end_publisher_flow_control_span()
|
| 419 |
+
else: # pragma: NO COVER
|
| 420 |
+
warnings.warn(
|
| 421 |
+
message="PubSubMessageWrapper is None. Not ending publisher flow control span.",
|
| 422 |
+
category=RuntimeWarning,
|
| 423 |
+
)
|
| 424 |
+
except exceptions.FlowControlLimitError as exc:
|
| 425 |
+
if self._open_telemetry_enabled:
|
| 426 |
+
if wrapper:
|
| 427 |
+
wrapper.end_publisher_flow_control_span(exc)
|
| 428 |
+
wrapper.end_create_span(exc)
|
| 429 |
+
else: # pragma: NO COVER
|
| 430 |
+
warnings.warn(
|
| 431 |
+
message="PubSubMessageWrapper is None. Not ending publisher create and flow control spans on FlowControlLimitError.",
|
| 432 |
+
category=RuntimeWarning,
|
| 433 |
+
)
|
| 434 |
+
|
| 435 |
+
future = futures.Future()
|
| 436 |
+
future.set_exception(exc)
|
| 437 |
+
return future
|
| 438 |
+
|
| 439 |
+
def on_publish_done(future):
|
| 440 |
+
self._flow_controller.release(message)
|
| 441 |
+
|
| 442 |
+
if retry is gapic_v1.method.DEFAULT: # if custom retry not passed in
|
| 443 |
+
retry = self.publisher_options.retry
|
| 444 |
+
|
| 445 |
+
if timeout is gapic_v1.method.DEFAULT: # if custom timeout not passed in
|
| 446 |
+
timeout = self.publisher_options.timeout
|
| 447 |
+
|
| 448 |
+
if self._open_telemetry_enabled:
|
| 449 |
+
if wrapper:
|
| 450 |
+
wrapper.start_publisher_batching_span()
|
| 451 |
+
else: # pragma: NO COVER
|
| 452 |
+
warnings.warn(
|
| 453 |
+
message="PublishMessageWrapper is None. Hence, not starting publisher batching span",
|
| 454 |
+
category=RuntimeWarning,
|
| 455 |
+
)
|
| 456 |
+
with self._batch_lock:
|
| 457 |
+
try:
|
| 458 |
+
if self._is_stopped:
|
| 459 |
+
raise RuntimeError("Cannot publish on a stopped publisher.")
|
| 460 |
+
|
| 461 |
+
# Set retry timeout to "infinite" when message ordering is enabled.
|
| 462 |
+
# Note that this then also impacts messages added with an empty
|
| 463 |
+
# ordering key.
|
| 464 |
+
if self._enable_message_ordering:
|
| 465 |
+
if retry is gapic_v1.method.DEFAULT:
|
| 466 |
+
# use the default retry for the publish GRPC method as a base
|
| 467 |
+
transport = self._transport
|
| 468 |
+
base_retry = transport._wrapped_methods[
|
| 469 |
+
transport.publish
|
| 470 |
+
]._retry
|
| 471 |
+
retry = base_retry.with_deadline(2.0**32)
|
| 472 |
+
# timeout needs to be overridden and set to infinite in
|
| 473 |
+
# addition to the retry deadline since both determine
|
| 474 |
+
# the duration for which retries are attempted.
|
| 475 |
+
timeout = 2.0**32
|
| 476 |
+
elif retry is not None:
|
| 477 |
+
retry = retry.with_deadline(2.0**32)
|
| 478 |
+
timeout = 2.0**32
|
| 479 |
+
|
| 480 |
+
# Delegate the publishing to the sequencer.
|
| 481 |
+
sequencer = self._get_or_create_sequencer(topic, ordering_key)
|
| 482 |
+
future = sequencer.publish(
|
| 483 |
+
wrapper=wrapper, retry=retry, timeout=timeout
|
| 484 |
+
)
|
| 485 |
+
future.add_done_callback(on_publish_done)
|
| 486 |
+
except BaseException as be:
|
| 487 |
+
# Exceptions can be thrown when attempting to add messages to
|
| 488 |
+
# the batch. If they're thrown, record them in publisher
|
| 489 |
+
# batching and create span, end the spans and bubble the
|
| 490 |
+
# exception up.
|
| 491 |
+
if self._open_telemetry_enabled:
|
| 492 |
+
if wrapper:
|
| 493 |
+
wrapper.end_publisher_batching_span(be)
|
| 494 |
+
wrapper.end_create_span(be)
|
| 495 |
+
else: # pragma: NO COVER
|
| 496 |
+
warnings.warn(
|
| 497 |
+
message="PublishMessageWrapper is None. Hence, not recording exception and ending publisher batching span and create span",
|
| 498 |
+
category=RuntimeWarning,
|
| 499 |
+
)
|
| 500 |
+
raise be
|
| 501 |
+
|
| 502 |
+
if self._open_telemetry_enabled:
|
| 503 |
+
if wrapper:
|
| 504 |
+
wrapper.end_publisher_batching_span()
|
| 505 |
+
else: # pragma: NO COVER
|
| 506 |
+
warnings.warn(
|
| 507 |
+
message="PublishMessageWrapper is None. Hence, not ending publisher batching span",
|
| 508 |
+
category=RuntimeWarning,
|
| 509 |
+
)
|
| 510 |
+
|
| 511 |
+
# Create a timer thread if necessary to enforce the batching
|
| 512 |
+
# timeout.
|
| 513 |
+
self._ensure_commit_timer_runs_no_lock()
|
| 514 |
+
|
| 515 |
+
return future
|
| 516 |
+
|
| 517 |
+
def ensure_cleanup_and_commit_timer_runs(self) -> None:
|
| 518 |
+
"""Ensure a cleanup/commit timer thread is running.
|
| 519 |
+
|
| 520 |
+
If a cleanup/commit timer thread is already running, this does nothing.
|
| 521 |
+
"""
|
| 522 |
+
with self._batch_lock:
|
| 523 |
+
self._ensure_commit_timer_runs_no_lock()
|
| 524 |
+
|
| 525 |
+
def _ensure_commit_timer_runs_no_lock(self) -> None:
|
| 526 |
+
"""Ensure a commit timer thread is running, without taking
|
| 527 |
+
_batch_lock.
|
| 528 |
+
|
| 529 |
+
_batch_lock must be held before calling this method.
|
| 530 |
+
"""
|
| 531 |
+
if not self._commit_thread and self.batch_settings.max_latency < float("inf"):
|
| 532 |
+
self._start_commit_thread()
|
| 533 |
+
|
| 534 |
+
def _start_commit_thread(self) -> None:
|
| 535 |
+
"""Start a new thread to actually wait and commit the sequencers."""
|
| 536 |
+
# NOTE: If the thread is *not* a daemon, a memory leak exists due to a CPython issue.
|
| 537 |
+
# https://github.com/googleapis/python-pubsub/issues/395#issuecomment-829910303
|
| 538 |
+
# https://github.com/googleapis/python-pubsub/issues/395#issuecomment-830092418
|
| 539 |
+
self._commit_thread = threading.Thread(
|
| 540 |
+
name="Thread-PubSubBatchCommitter",
|
| 541 |
+
target=self._wait_and_commit_sequencers,
|
| 542 |
+
daemon=True,
|
| 543 |
+
)
|
| 544 |
+
self._commit_thread.start()
|
| 545 |
+
|
| 546 |
+
def _wait_and_commit_sequencers(self) -> None:
|
| 547 |
+
"""Wait up to the batching timeout, and commit all sequencers."""
|
| 548 |
+
# Sleep for however long we should be waiting.
|
| 549 |
+
time.sleep(self.batch_settings.max_latency)
|
| 550 |
+
_LOGGER.debug("Commit thread is waking up")
|
| 551 |
+
|
| 552 |
+
with self._batch_lock:
|
| 553 |
+
if self._is_stopped:
|
| 554 |
+
return
|
| 555 |
+
self._commit_sequencers()
|
| 556 |
+
self._commit_thread = None
|
| 557 |
+
|
| 558 |
+
def _commit_sequencers(self) -> None:
|
| 559 |
+
"""Clean up finished sequencers and commit the rest."""
|
| 560 |
+
finished_sequencer_keys = [
|
| 561 |
+
key
|
| 562 |
+
for key, sequencer in self._sequencers.items()
|
| 563 |
+
if sequencer.is_finished()
|
| 564 |
+
]
|
| 565 |
+
for sequencer_key in finished_sequencer_keys:
|
| 566 |
+
del self._sequencers[sequencer_key]
|
| 567 |
+
|
| 568 |
+
for sequencer in self._sequencers.values():
|
| 569 |
+
sequencer.commit()
|
| 570 |
+
|
| 571 |
+
def stop(self) -> None:
|
| 572 |
+
"""Immediately publish all outstanding messages.
|
| 573 |
+
|
| 574 |
+
Asynchronously sends all outstanding messages and
|
| 575 |
+
prevents future calls to `publish()`. Method should
|
| 576 |
+
be invoked prior to deleting this `Client()` object
|
| 577 |
+
in order to ensure that no pending messages are lost.
|
| 578 |
+
|
| 579 |
+
.. note::
|
| 580 |
+
|
| 581 |
+
This method is non-blocking. Use `Future()` objects
|
| 582 |
+
returned by `publish()` to make sure all publish
|
| 583 |
+
requests completed, either in success or error.
|
| 584 |
+
|
| 585 |
+
Raises:
|
| 586 |
+
RuntimeError:
|
| 587 |
+
If called after publisher has been stopped by a `stop()` method
|
| 588 |
+
call.
|
| 589 |
+
"""
|
| 590 |
+
with self._batch_lock:
|
| 591 |
+
if self._is_stopped:
|
| 592 |
+
raise RuntimeError("Cannot stop a publisher already stopped.")
|
| 593 |
+
|
| 594 |
+
self._is_stopped = True
|
| 595 |
+
|
| 596 |
+
for sequencer in self._sequencers.values():
|
| 597 |
+
sequencer.stop()
|
| 598 |
+
|
| 599 |
+
# Used only for testing.
|
| 600 |
+
def _set_batch(
|
| 601 |
+
self, topic: str, batch: "_batch.thread.Batch", ordering_key: str = ""
|
| 602 |
+
) -> None:
|
| 603 |
+
sequencer = self._get_or_create_sequencer(topic, ordering_key)
|
| 604 |
+
sequencer._set_batch(batch)
|
| 605 |
+
|
| 606 |
+
# Used only for testing.
|
| 607 |
+
def _set_batch_class(self, batch_class: Type) -> None:
|
| 608 |
+
self._batch_class = batch_class
|
| 609 |
+
|
| 610 |
+
# Used only for testing.
|
| 611 |
+
def _set_sequencer(
|
| 612 |
+
self, topic: str, sequencer: SequencerType, ordering_key: str = ""
|
| 613 |
+
) -> None:
|
| 614 |
+
sequencer_key = (topic, ordering_key)
|
| 615 |
+
self._sequencers[sequencer_key] = sequencer
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/exceptions.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
from google.api_core.exceptions import GoogleAPICallError
|
| 18 |
+
|
| 19 |
+
from google.cloud.pubsub_v1.exceptions import TimeoutError
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class PublishError(GoogleAPICallError):
|
| 23 |
+
pass
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class MessageTooLargeError(ValueError):
|
| 27 |
+
"""Attempt to publish a message that would exceed the server max size limit."""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class PublishToPausedOrderingKeyException(Exception):
|
| 31 |
+
"""Publish attempted to paused ordering key. To resume publishing, call
|
| 32 |
+
the resumePublish method on the publisher Client object with this
|
| 33 |
+
ordering key. Ordering keys are paused if an unrecoverable error
|
| 34 |
+
occurred during publish of a batch for that key.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
def __init__(self, ordering_key: str):
|
| 38 |
+
self.ordering_key = ordering_key
|
| 39 |
+
super(PublishToPausedOrderingKeyException, self).__init__()
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class FlowControlLimitError(Exception):
|
| 43 |
+
"""An action resulted in exceeding the flow control limits."""
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
__all__ = (
|
| 47 |
+
"FlowControlLimitError",
|
| 48 |
+
"MessageTooLargeError",
|
| 49 |
+
"PublishError",
|
| 50 |
+
"TimeoutError",
|
| 51 |
+
"PublishToPausedOrderingKeyException",
|
| 52 |
+
)
|
loan-advisor-agent/.venv/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import logging
|
| 16 |
+
import threading
|
| 17 |
+
import warnings
|
| 18 |
+
from collections import OrderedDict
|
| 19 |
+
from typing import Dict, Optional, Type
|
| 20 |
+
|
| 21 |
+
from google.cloud.pubsub_v1 import types
|
| 22 |
+
from google.cloud.pubsub_v1.publisher import exceptions
|
| 23 |
+
|
| 24 |
+
_LOGGER = logging.getLogger(__name__)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
MessageType = Type[types.PubsubMessage] # type: ignore
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class _QuantityReservation:
|
| 31 |
+
"""A (partial) reservation of quantifiable resources."""
|
| 32 |
+
|
| 33 |
+
def __init__(self, bytes_reserved: int, bytes_needed: int, has_slot: bool):
|
| 34 |
+
self.bytes_reserved = bytes_reserved
|
| 35 |
+
self.bytes_needed = bytes_needed
|
| 36 |
+
self.has_slot = has_slot
|
| 37 |
+
|
| 38 |
+
def __repr__(self):
|
| 39 |
+
return (
|
| 40 |
+
f"{type(self).__name__}("
|
| 41 |
+
f"bytes_reserved={self.bytes_reserved}, "
|
| 42 |
+
f"bytes_needed={self.bytes_needed}, "
|
| 43 |
+
f"has_slot={self.has_slot})"
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class FlowController(object):
|
| 48 |
+
"""A class used to control the flow of messages passing through it.
|
| 49 |
+
|
| 50 |
+
Args:
|
| 51 |
+
settings: Desired flow control configuration.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
def __init__(self, settings: types.PublishFlowControl):
|
| 55 |
+
self._settings = settings
|
| 56 |
+
|
| 57 |
+
# Load statistics. They represent the number of messages added, but not
|
| 58 |
+
# yet released (and their total size).
|
| 59 |
+
self._message_count = 0
|
| 60 |
+
self._total_bytes = 0
|
| 61 |
+
|
| 62 |
+
# A FIFO queue of threads blocked on adding a message that also tracks their
|
| 63 |
+
# reservations of available flow control bytes and message slots.
|
| 64 |
+
# Only relevant if the configured limit exceeded behavior is BLOCK.
|
| 65 |
+
self._waiting: Dict[threading.Thread, _QuantityReservation] = OrderedDict()
|
| 66 |
+
|
| 67 |
+
self._reserved_bytes = 0
|
| 68 |
+
self._reserved_slots = 0
|
| 69 |
+
|
| 70 |
+
# The lock is used to protect all internal state (message and byte count,
|
| 71 |
+
# waiting threads to add, etc.).
|
| 72 |
+
self._operational_lock = threading.Lock()
|
| 73 |
+
|
| 74 |
+
# The condition for blocking the flow if capacity is exceeded.
|
| 75 |
+
self._has_capacity = threading.Condition(lock=self._operational_lock)
|
| 76 |
+
|
| 77 |
+
def add(self, message: MessageType) -> None:
|
| 78 |
+
"""Add a message to flow control.
|
| 79 |
+
|
| 80 |
+
Adding a message updates the internal load statistics, and an action is
|
| 81 |
+
taken if these limits are exceeded (depending on the flow control settings).
|
| 82 |
+
|
| 83 |
+
Args:
|
| 84 |
+
message:
|
| 85 |
+
The message entering the flow control.
|
| 86 |
+
|
| 87 |
+
Raises:
|
| 88 |
+
:exception:`~pubsub_v1.publisher.exceptions.FlowControlLimitError`:
|
| 89 |
+
Raised when the desired action is
|
| 90 |
+
:attr:`~google.cloud.pubsub_v1.types.LimitExceededBehavior.ERROR` and
|
| 91 |
+
the message would exceed flow control limits, or when the desired action
|
| 92 |
+
is :attr:`~google.cloud.pubsub_v1.types.LimitExceededBehavior.BLOCK` and
|
| 93 |
+
the message would block forever against the flow control limits.
|
| 94 |
+
"""
|
| 95 |
+
if self._settings.limit_exceeded_behavior == types.LimitExceededBehavior.IGNORE:
|
| 96 |
+
return
|
| 97 |
+
|
| 98 |
+
with self._operational_lock:
|
| 99 |
+
if not self._would_overflow(message):
|
| 100 |
+
self._message_count += 1
|
| 101 |
+
self._total_bytes += message._pb.ByteSize()
|
| 102 |
+
return
|
| 103 |
+
|
| 104 |
+
# Adding a message would overflow, react.
|
| 105 |
+
if (
|
| 106 |
+
self._settings.limit_exceeded_behavior
|
| 107 |
+
== types.LimitExceededBehavior.ERROR
|
| 108 |
+
):
|
| 109 |
+
# Raising an error means rejecting a message, thus we do not
|
| 110 |
+
# add anything to the existing load, but we do report the would-be
|
| 111 |
+
# load if we accepted the message.
|
| 112 |
+
load_info = self._load_info(
|
| 113 |
+
message_count=self._message_count + 1,
|
| 114 |
+
total_bytes=self._total_bytes + message._pb.ByteSize(),
|
| 115 |
+
)
|
| 116 |
+
error_msg = "Flow control limits would be exceeded - {}.".format(
|
| 117 |
+
load_info
|
| 118 |
+
)
|
| 119 |
+
raise exceptions.FlowControlLimitError(error_msg)
|
| 120 |
+
|
| 121 |
+
assert (
|
| 122 |
+
self._settings.limit_exceeded_behavior
|
| 123 |
+
== types.LimitExceededBehavior.BLOCK
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
# Sanity check - if a message exceeds total flow control limits all
|
| 127 |
+
# by itself, it would block forever, thus raise error.
|
| 128 |
+
if (
|
| 129 |
+
message._pb.ByteSize() > self._settings.byte_limit
|
| 130 |
+
or self._settings.message_limit < 1
|
| 131 |
+
):
|
| 132 |
+
load_info = self._load_info(
|
| 133 |
+
message_count=1, total_bytes=message._pb.ByteSize()
|
| 134 |
+
)
|
| 135 |
+
error_msg = (
|
| 136 |
+
"Total flow control limits too low for the message, "
|
| 137 |
+
"would block forever - {}.".format(load_info)
|
| 138 |
+
)
|
| 139 |
+
raise exceptions.FlowControlLimitError(error_msg)
|
| 140 |
+
|
| 141 |
+
current_thread = threading.current_thread()
|
| 142 |
+
|
| 143 |
+
while self._would_overflow(message):
|
| 144 |
+
if current_thread not in self._waiting:
|
| 145 |
+
reservation = _QuantityReservation(
|
| 146 |
+
bytes_reserved=0,
|
| 147 |
+
bytes_needed=message._pb.ByteSize(),
|
| 148 |
+
has_slot=False,
|
| 149 |
+
)
|
| 150 |
+
self._waiting[current_thread] = reservation # Will be placed last.
|
| 151 |
+
|
| 152 |
+
_LOGGER.debug(
|
| 153 |
+
"Blocking until there is enough free capacity in the flow - "
|
| 154 |
+
"{}.".format(self._load_info())
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
self._has_capacity.wait()
|
| 158 |
+
|
| 159 |
+
_LOGGER.debug(
|
| 160 |
+
"Woke up from waiting on free capacity in the flow - {}.".format(
|
| 161 |
+
self._load_info()
|
| 162 |
+
)
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
# Message accepted, increase the load and remove thread stats.
|
| 166 |
+
self._message_count += 1
|
| 167 |
+
self._total_bytes += message._pb.ByteSize()
|
| 168 |
+
self._reserved_bytes -= self._waiting[current_thread].bytes_reserved
|
| 169 |
+
self._reserved_slots -= 1
|
| 170 |
+
del self._waiting[current_thread]
|
| 171 |
+
|
| 172 |
+
def release(self, message: MessageType) -> None:
|
| 173 |
+
"""Release a mesage from flow control.
|
| 174 |
+
|
| 175 |
+
Args:
|
| 176 |
+
message:
|
| 177 |
+
The message entering the flow control.
|
| 178 |
+
"""
|
| 179 |
+
if self._settings.limit_exceeded_behavior == types.LimitExceededBehavior.IGNORE:
|
| 180 |
+
return
|
| 181 |
+
|
| 182 |
+
with self._operational_lock:
|
| 183 |
+
# Releasing a message decreases the load.
|
| 184 |
+
self._message_count -= 1
|
| 185 |
+
self._total_bytes -= message._pb.ByteSize()
|
| 186 |
+
|
| 187 |
+
if self._message_count < 0 or self._total_bytes < 0:
|
| 188 |
+
warnings.warn(
|
| 189 |
+
"Releasing a message that was never added or already released.",
|
| 190 |
+
category=RuntimeWarning,
|
| 191 |
+
stacklevel=2,
|
| 192 |
+
)
|
| 193 |
+
self._message_count = max(0, self._message_count)
|
| 194 |
+
self._total_bytes = max(0, self._total_bytes)
|
| 195 |
+
|
| 196 |
+
self._distribute_available_capacity()
|
| 197 |
+
|
| 198 |
+
# If at least one thread waiting to add() can be unblocked, wake them up.
|
| 199 |
+
if self._ready_to_unblock():
|
| 200 |
+
_LOGGER.debug("Notifying threads waiting to add messages to flow.")
|
| 201 |
+
self._has_capacity.notify_all()
|
| 202 |
+
|
| 203 |
+
def _distribute_available_capacity(self) -> None:
|
| 204 |
+
"""Distribute available capacity among the waiting threads in FIFO order.
|
| 205 |
+
|
| 206 |
+
The method assumes that the caller has obtained ``_operational_lock``.
|
| 207 |
+
"""
|
| 208 |
+
available_slots = (
|
| 209 |
+
self._settings.message_limit - self._message_count - self._reserved_slots
|
| 210 |
+
)
|
| 211 |
+
available_bytes = (
|
| 212 |
+
self._settings.byte_limit - self._total_bytes - self._reserved_bytes
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
for reservation in self._waiting.values():
|
| 216 |
+
if available_slots <= 0 and available_bytes <= 0:
|
| 217 |
+
break # Santa is now empty-handed, better luck next time.
|
| 218 |
+
|
| 219 |
+
# Distribute any free slots.
|
| 220 |
+
if available_slots > 0 and not reservation.has_slot:
|
| 221 |
+
reservation.has_slot = True
|
| 222 |
+
self._reserved_slots += 1
|
| 223 |
+
available_slots -= 1
|
| 224 |
+
|
| 225 |
+
# Distribute any free bytes.
|
| 226 |
+
if available_bytes <= 0:
|
| 227 |
+
continue
|
| 228 |
+
|
| 229 |
+
bytes_still_needed = reservation.bytes_needed - reservation.bytes_reserved
|
| 230 |
+
|
| 231 |
+
if bytes_still_needed < 0: # Sanity check for any internal inconsistencies.
|
| 232 |
+
msg = "Too many bytes reserved: {} / {}".format(
|
| 233 |
+
reservation.bytes_reserved, reservation.bytes_needed
|
| 234 |
+
)
|
| 235 |
+
warnings.warn(msg, category=RuntimeWarning)
|
| 236 |
+
bytes_still_needed = 0
|
| 237 |
+
|
| 238 |
+
can_give = min(bytes_still_needed, available_bytes)
|
| 239 |
+
reservation.bytes_reserved += can_give
|
| 240 |
+
self._reserved_bytes += can_give
|
| 241 |
+
available_bytes -= can_give
|
| 242 |
+
|
| 243 |
+
def _ready_to_unblock(self) -> bool:
|
| 244 |
+
"""Determine if any of the threads waiting to add a message can proceed.
|
| 245 |
+
|
| 246 |
+
The method assumes that the caller has obtained ``_operational_lock``.
|
| 247 |
+
"""
|
| 248 |
+
if self._waiting:
|
| 249 |
+
# It's enough to only check the head of the queue, because FIFO
|
| 250 |
+
# distribution of any free capacity.
|
| 251 |
+
first_reservation = next(iter(self._waiting.values()))
|
| 252 |
+
return (
|
| 253 |
+
first_reservation.bytes_reserved >= first_reservation.bytes_needed
|
| 254 |
+
and first_reservation.has_slot
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
return False
|
| 258 |
+
|
| 259 |
+
def _would_overflow(self, message: MessageType) -> bool:
|
| 260 |
+
"""Determine if accepting a message would exceed flow control limits.
|
| 261 |
+
|
| 262 |
+
The method assumes that the caller has obtained ``_operational_lock``.
|
| 263 |
+
|
| 264 |
+
Args:
|
| 265 |
+
message: The message entering the flow control.
|
| 266 |
+
"""
|
| 267 |
+
reservation = self._waiting.get(threading.current_thread())
|
| 268 |
+
|
| 269 |
+
if reservation:
|
| 270 |
+
enough_reserved = reservation.bytes_reserved >= reservation.bytes_needed
|
| 271 |
+
has_slot = reservation.has_slot
|
| 272 |
+
else:
|
| 273 |
+
enough_reserved = False
|
| 274 |
+
has_slot = False
|
| 275 |
+
|
| 276 |
+
bytes_taken = self._total_bytes + self._reserved_bytes + message._pb.ByteSize()
|
| 277 |
+
size_overflow = bytes_taken > self._settings.byte_limit and not enough_reserved
|
| 278 |
+
|
| 279 |
+
msg_count_overflow = not has_slot and (
|
| 280 |
+
(self._message_count + self._reserved_slots + 1)
|
| 281 |
+
> self._settings.message_limit
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
return size_overflow or msg_count_overflow
|
| 285 |
+
|
| 286 |
+
def _load_info(
|
| 287 |
+
self, message_count: Optional[int] = None, total_bytes: Optional[int] = None
|
| 288 |
+
) -> str:
|
| 289 |
+
"""Return the current flow control load information.
|
| 290 |
+
|
| 291 |
+
The caller can optionally adjust some of the values to fit its reporting
|
| 292 |
+
needs.
|
| 293 |
+
|
| 294 |
+
The method assumes that the caller has obtained ``_operational_lock``.
|
| 295 |
+
|
| 296 |
+
Args:
|
| 297 |
+
message_count:
|
| 298 |
+
The value to override the current message count with.
|
| 299 |
+
total_bytes:
|
| 300 |
+
The value to override the current total bytes with.
|
| 301 |
+
"""
|
| 302 |
+
if message_count is None:
|
| 303 |
+
message_count = self._message_count
|
| 304 |
+
|
| 305 |
+
if total_bytes is None:
|
| 306 |
+
total_bytes = self._total_bytes
|
| 307 |
+
|
| 308 |
+
return (
|
| 309 |
+
f"messages: {message_count} / {self._settings.message_limit} "
|
| 310 |
+
f"(reserved: {self._reserved_slots}), "
|
| 311 |
+
f"bytes: {total_bytes} / {self._settings.byte_limit} "
|
| 312 |
+
f"(reserved: {self._reserved_bytes})"
|
| 313 |
+
)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/publisher/futures.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
import typing
|
| 18 |
+
from typing import Any, Callable, Union
|
| 19 |
+
|
| 20 |
+
from google.cloud.pubsub_v1 import futures
|
| 21 |
+
|
| 22 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 23 |
+
from google.cloud import pubsub_v1
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class Future(futures.Future):
|
| 27 |
+
"""This future object is returned from asychronous Pub/Sub publishing
|
| 28 |
+
calls.
|
| 29 |
+
|
| 30 |
+
Calling :meth:`result` will resolve the future by returning the message
|
| 31 |
+
ID, unless an error occurs.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
def cancel(self) -> bool:
|
| 35 |
+
"""Actions in Pub/Sub generally may not be canceled.
|
| 36 |
+
|
| 37 |
+
This method always returns ``False``.
|
| 38 |
+
"""
|
| 39 |
+
return False
|
| 40 |
+
|
| 41 |
+
def cancelled(self) -> bool:
|
| 42 |
+
"""Actions in Pub/Sub generally may not be canceled.
|
| 43 |
+
|
| 44 |
+
This method always returns ``False``.
|
| 45 |
+
"""
|
| 46 |
+
return False
|
| 47 |
+
|
| 48 |
+
def result(self, timeout: Union[int, float, None] = None) -> str:
|
| 49 |
+
"""Return the message ID or raise an exception.
|
| 50 |
+
|
| 51 |
+
This blocks until the message has been published successfully and
|
| 52 |
+
returns the message ID unless an exception is raised.
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
timeout: The number of seconds before this call
|
| 56 |
+
times out and raises TimeoutError.
|
| 57 |
+
|
| 58 |
+
Returns:
|
| 59 |
+
The message ID.
|
| 60 |
+
|
| 61 |
+
Raises:
|
| 62 |
+
concurrent.futures.TimeoutError: If the request times out.
|
| 63 |
+
Exception: For undefined exceptions in the underlying
|
| 64 |
+
call execution.
|
| 65 |
+
"""
|
| 66 |
+
return super().result(timeout=timeout)
|
| 67 |
+
|
| 68 |
+
# This exists to make the type checkers happy.
|
| 69 |
+
def add_done_callback(
|
| 70 |
+
self, callback: Callable[["pubsub_v1.publisher.futures.Future"], Any]
|
| 71 |
+
) -> None:
|
| 72 |
+
"""Attach a callable that will be called when the future finishes.
|
| 73 |
+
|
| 74 |
+
Args:
|
| 75 |
+
callback:
|
| 76 |
+
A callable that will be called with this future as its only
|
| 77 |
+
argument when the future completes or is cancelled. The callable
|
| 78 |
+
will always be called by a thread in the same process in which
|
| 79 |
+
it was added. If the future has already completed or been
|
| 80 |
+
cancelled then the callable will be called immediately. These
|
| 81 |
+
callables are called in the order that they were added.
|
| 82 |
+
"""
|
| 83 |
+
return super().add_done_callback(callback) # type: ignore
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
from google.cloud.pubsub_v1.subscriber.client import Client
|
| 18 |
+
|
| 19 |
+
__all__ = ("Client",)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/__init__.py
ADDED
|
File without changes
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py
ADDED
|
@@ -0,0 +1,657 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import, division
|
| 16 |
+
|
| 17 |
+
import functools
|
| 18 |
+
import itertools
|
| 19 |
+
import logging
|
| 20 |
+
import math
|
| 21 |
+
import threading
|
| 22 |
+
import time
|
| 23 |
+
import typing
|
| 24 |
+
import warnings
|
| 25 |
+
from typing import List, Optional, Sequence, Union
|
| 26 |
+
|
| 27 |
+
from google.api_core.retry import exponential_sleep_generator
|
| 28 |
+
from opentelemetry import trace
|
| 29 |
+
|
| 30 |
+
from google.cloud.pubsub_v1.open_telemetry.subscribe_opentelemetry import (
|
| 31 |
+
start_ack_span,
|
| 32 |
+
start_nack_span,
|
| 33 |
+
)
|
| 34 |
+
from google.cloud.pubsub_v1.subscriber._protocol import helper_threads, requests
|
| 35 |
+
from google.cloud.pubsub_v1.subscriber.exceptions import (
|
| 36 |
+
AcknowledgeStatus,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 40 |
+
import queue
|
| 41 |
+
|
| 42 |
+
from google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager import (
|
| 43 |
+
StreamingPullManager,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
RequestItem = Union[
|
| 48 |
+
requests.AckRequest,
|
| 49 |
+
requests.DropRequest,
|
| 50 |
+
requests.LeaseRequest,
|
| 51 |
+
requests.ModAckRequest,
|
| 52 |
+
requests.NackRequest,
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
_LOGGER = logging.getLogger(__name__)
|
| 57 |
+
_CALLBACK_WORKER_NAME = "Thread-CallbackRequestDispatcher"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
_MAX_BATCH_SIZE = 100
|
| 61 |
+
"""The maximum number of requests to process and dispatch at a time."""
|
| 62 |
+
|
| 63 |
+
_MAX_BATCH_LATENCY = 0.01
|
| 64 |
+
"""The maximum amount of time in seconds to wait for additional request items
|
| 65 |
+
before processing the next batch of requests."""
|
| 66 |
+
|
| 67 |
+
_ACK_IDS_BATCH_SIZE = 1000
|
| 68 |
+
"""The maximum number of ACK IDs to send in a single StreamingPullRequest.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
_MIN_EXACTLY_ONCE_DELIVERY_ACK_MODACK_RETRY_DURATION_SECS = 1
|
| 72 |
+
"""The time to wait for the first retry of failed acks and modacks when exactly-once
|
| 73 |
+
delivery is enabled."""
|
| 74 |
+
|
| 75 |
+
_MAX_EXACTLY_ONCE_DELIVERY_ACK_MODACK_RETRY_DURATION_SECS = 10 * 60
|
| 76 |
+
"""The maximum amount of time in seconds to retry failed acks and modacks when
|
| 77 |
+
exactly-once delivery is enabled."""
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class Dispatcher(object):
|
| 81 |
+
def __init__(self, manager: "StreamingPullManager", queue: "queue.Queue"):
|
| 82 |
+
self._manager = manager
|
| 83 |
+
self._queue = queue
|
| 84 |
+
self._thread: Optional[threading.Thread] = None
|
| 85 |
+
self._operational_lock = threading.Lock()
|
| 86 |
+
|
| 87 |
+
def start(self) -> None:
|
| 88 |
+
"""Start a thread to dispatch requests queued up by callbacks.
|
| 89 |
+
|
| 90 |
+
Spawns a thread to run :meth:`dispatch_callback`.
|
| 91 |
+
"""
|
| 92 |
+
with self._operational_lock:
|
| 93 |
+
if self._thread is not None:
|
| 94 |
+
raise ValueError("Dispatcher is already running.")
|
| 95 |
+
|
| 96 |
+
worker = helper_threads.QueueCallbackWorker(
|
| 97 |
+
self._queue,
|
| 98 |
+
self.dispatch_callback,
|
| 99 |
+
max_items=_MAX_BATCH_SIZE,
|
| 100 |
+
max_latency=_MAX_BATCH_LATENCY,
|
| 101 |
+
)
|
| 102 |
+
# Create and start the helper thread.
|
| 103 |
+
thread = threading.Thread(name=_CALLBACK_WORKER_NAME, target=worker)
|
| 104 |
+
thread.daemon = True
|
| 105 |
+
thread.start()
|
| 106 |
+
_LOGGER.debug("Started helper thread %s", thread.name)
|
| 107 |
+
self._thread = thread
|
| 108 |
+
|
| 109 |
+
def stop(self) -> None:
|
| 110 |
+
with self._operational_lock:
|
| 111 |
+
if self._thread is not None:
|
| 112 |
+
# Signal the worker to stop by queueing a "poison pill"
|
| 113 |
+
self._queue.put(helper_threads.STOP)
|
| 114 |
+
self._thread.join()
|
| 115 |
+
|
| 116 |
+
self._thread = None
|
| 117 |
+
|
| 118 |
+
def dispatch_callback(self, items: Sequence[RequestItem]) -> None:
|
| 119 |
+
"""Map the callback request to the appropriate gRPC request.
|
| 120 |
+
|
| 121 |
+
Args:
|
| 122 |
+
items:
|
| 123 |
+
Queued requests to dispatch.
|
| 124 |
+
"""
|
| 125 |
+
lease_requests: List[requests.LeaseRequest] = []
|
| 126 |
+
modack_requests: List[requests.ModAckRequest] = []
|
| 127 |
+
ack_requests: List[requests.AckRequest] = []
|
| 128 |
+
nack_requests: List[requests.NackRequest] = []
|
| 129 |
+
drop_requests: List[requests.DropRequest] = []
|
| 130 |
+
|
| 131 |
+
lease_ids = set()
|
| 132 |
+
modack_ids = set()
|
| 133 |
+
ack_ids = set()
|
| 134 |
+
nack_ids = set()
|
| 135 |
+
drop_ids = set()
|
| 136 |
+
exactly_once_delivery_enabled = self._manager._exactly_once_delivery_enabled()
|
| 137 |
+
|
| 138 |
+
for item in items:
|
| 139 |
+
if isinstance(item, requests.LeaseRequest):
|
| 140 |
+
if (
|
| 141 |
+
item.ack_id not in lease_ids
|
| 142 |
+
): # LeaseRequests have no futures to handle.
|
| 143 |
+
lease_ids.add(item.ack_id)
|
| 144 |
+
lease_requests.append(item)
|
| 145 |
+
elif isinstance(item, requests.ModAckRequest):
|
| 146 |
+
if item.ack_id in modack_ids:
|
| 147 |
+
self._handle_duplicate_request_future(
|
| 148 |
+
exactly_once_delivery_enabled, item
|
| 149 |
+
)
|
| 150 |
+
else:
|
| 151 |
+
modack_ids.add(item.ack_id)
|
| 152 |
+
modack_requests.append(item)
|
| 153 |
+
elif isinstance(item, requests.AckRequest):
|
| 154 |
+
if item.ack_id in ack_ids:
|
| 155 |
+
self._handle_duplicate_request_future(
|
| 156 |
+
exactly_once_delivery_enabled, item
|
| 157 |
+
)
|
| 158 |
+
else:
|
| 159 |
+
ack_ids.add(item.ack_id)
|
| 160 |
+
ack_requests.append(item)
|
| 161 |
+
elif isinstance(item, requests.NackRequest):
|
| 162 |
+
if item.ack_id in nack_ids:
|
| 163 |
+
self._handle_duplicate_request_future(
|
| 164 |
+
exactly_once_delivery_enabled, item
|
| 165 |
+
)
|
| 166 |
+
else:
|
| 167 |
+
nack_ids.add(item.ack_id)
|
| 168 |
+
nack_requests.append(item)
|
| 169 |
+
elif isinstance(item, requests.DropRequest):
|
| 170 |
+
if (
|
| 171 |
+
item.ack_id not in drop_ids
|
| 172 |
+
): # DropRequests have no futures to handle.
|
| 173 |
+
drop_ids.add(item.ack_id)
|
| 174 |
+
drop_requests.append(item)
|
| 175 |
+
else:
|
| 176 |
+
warnings.warn(
|
| 177 |
+
f'Skipping unknown request item of type "{type(item)}"',
|
| 178 |
+
category=RuntimeWarning,
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
_LOGGER.debug("Handling %d batched requests", len(items))
|
| 182 |
+
|
| 183 |
+
if lease_requests:
|
| 184 |
+
self.lease(lease_requests)
|
| 185 |
+
|
| 186 |
+
if modack_requests:
|
| 187 |
+
self.modify_ack_deadline(modack_requests)
|
| 188 |
+
|
| 189 |
+
# Note: Drop and ack *must* be after lease. It's possible to get both
|
| 190 |
+
# the lease and the ack/drop request in the same batch.
|
| 191 |
+
if ack_requests:
|
| 192 |
+
self.ack(ack_requests)
|
| 193 |
+
|
| 194 |
+
if nack_requests:
|
| 195 |
+
self.nack(nack_requests)
|
| 196 |
+
|
| 197 |
+
if drop_requests:
|
| 198 |
+
self.drop(drop_requests)
|
| 199 |
+
|
| 200 |
+
def _handle_duplicate_request_future(
|
| 201 |
+
self,
|
| 202 |
+
exactly_once_delivery_enabled: bool,
|
| 203 |
+
item: Union[requests.AckRequest, requests.ModAckRequest, requests.NackRequest],
|
| 204 |
+
) -> None:
|
| 205 |
+
_LOGGER.debug(
|
| 206 |
+
"This is a duplicate %s with the same ack_id: %s.",
|
| 207 |
+
type(item),
|
| 208 |
+
item.ack_id,
|
| 209 |
+
)
|
| 210 |
+
if item.future:
|
| 211 |
+
if exactly_once_delivery_enabled:
|
| 212 |
+
item.future.set_exception(
|
| 213 |
+
ValueError(f"Duplicate ack_id for {type(item)}")
|
| 214 |
+
)
|
| 215 |
+
# Futures may be present even with exactly-once delivery
|
| 216 |
+
# disabled, in transition periods after the setting is changed on
|
| 217 |
+
# the subscription.
|
| 218 |
+
else:
|
| 219 |
+
# When exactly-once delivery is NOT enabled, acks/modacks are considered
|
| 220 |
+
# best-effort, so the future should succeed even though this is a duplicate.
|
| 221 |
+
item.future.set_result(AcknowledgeStatus.SUCCESS)
|
| 222 |
+
|
| 223 |
+
def ack(self, items: Sequence[requests.AckRequest]) -> None:
|
| 224 |
+
"""Acknowledge the given messages.
|
| 225 |
+
|
| 226 |
+
Args:
|
| 227 |
+
items: The items to acknowledge.
|
| 228 |
+
"""
|
| 229 |
+
# If we got timing information, add it to the histogram.
|
| 230 |
+
for item in items:
|
| 231 |
+
time_to_ack = item.time_to_ack
|
| 232 |
+
if time_to_ack is not None:
|
| 233 |
+
self._manager.ack_histogram.add(time_to_ack)
|
| 234 |
+
|
| 235 |
+
# We must potentially split the request into multiple smaller requests
|
| 236 |
+
# to avoid the server-side max request size limit.
|
| 237 |
+
items_gen = iter(items)
|
| 238 |
+
ack_ids_gen = (item.ack_id for item in items)
|
| 239 |
+
total_chunks = int(math.ceil(len(items) / _ACK_IDS_BATCH_SIZE))
|
| 240 |
+
subscription_id: Optional[str] = None
|
| 241 |
+
project_id: Optional[str] = None
|
| 242 |
+
for item in items:
|
| 243 |
+
if item.opentelemetry_data:
|
| 244 |
+
item.opentelemetry_data.add_subscribe_span_event("ack start")
|
| 245 |
+
if subscription_id is None:
|
| 246 |
+
subscription_id = item.opentelemetry_data.subscription_id
|
| 247 |
+
if project_id is None:
|
| 248 |
+
project_id = item.opentelemetry_data.project_id
|
| 249 |
+
|
| 250 |
+
for _ in range(total_chunks):
|
| 251 |
+
ack_reqs_dict = {
|
| 252 |
+
req.ack_id: req
|
| 253 |
+
for req in itertools.islice(items_gen, _ACK_IDS_BATCH_SIZE)
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
subscribe_links: List[trace.Link] = []
|
| 257 |
+
subscribe_spans: List[trace.Span] = []
|
| 258 |
+
for ack_req in ack_reqs_dict.values():
|
| 259 |
+
if ack_req.opentelemetry_data:
|
| 260 |
+
subscribe_span: Optional[trace.Span] = (
|
| 261 |
+
ack_req.opentelemetry_data.subscribe_span
|
| 262 |
+
)
|
| 263 |
+
if (
|
| 264 |
+
subscribe_span
|
| 265 |
+
and subscribe_span.get_span_context().trace_flags.sampled
|
| 266 |
+
):
|
| 267 |
+
subscribe_links.append(
|
| 268 |
+
trace.Link(subscribe_span.get_span_context())
|
| 269 |
+
)
|
| 270 |
+
subscribe_spans.append(subscribe_span)
|
| 271 |
+
ack_span: Optional[trace.Span] = None
|
| 272 |
+
if subscription_id and project_id:
|
| 273 |
+
ack_span = start_ack_span(
|
| 274 |
+
subscription_id,
|
| 275 |
+
len(ack_reqs_dict),
|
| 276 |
+
project_id,
|
| 277 |
+
subscribe_links,
|
| 278 |
+
)
|
| 279 |
+
if (
|
| 280 |
+
ack_span and ack_span.get_span_context().trace_flags.sampled
|
| 281 |
+
): # pragma: NO COVER
|
| 282 |
+
ack_span_context: trace.SpanContext = ack_span.get_span_context()
|
| 283 |
+
for subscribe_span in subscribe_spans:
|
| 284 |
+
subscribe_span.add_link(
|
| 285 |
+
context=ack_span_context,
|
| 286 |
+
attributes={
|
| 287 |
+
"messaging.operation.name": "ack",
|
| 288 |
+
},
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
requests_completed, requests_to_retry = self._manager.send_unary_ack(
|
| 292 |
+
ack_ids=list(itertools.islice(ack_ids_gen, _ACK_IDS_BATCH_SIZE)),
|
| 293 |
+
ack_reqs_dict=ack_reqs_dict,
|
| 294 |
+
)
|
| 295 |
+
if ack_span:
|
| 296 |
+
ack_span.end()
|
| 297 |
+
|
| 298 |
+
for completed_ack in requests_completed:
|
| 299 |
+
if completed_ack.opentelemetry_data:
|
| 300 |
+
completed_ack.opentelemetry_data.add_subscribe_span_event("ack end")
|
| 301 |
+
completed_ack.opentelemetry_data.set_subscribe_span_result("acked")
|
| 302 |
+
completed_ack.opentelemetry_data.end_subscribe_span()
|
| 303 |
+
|
| 304 |
+
# Remove the completed messages from lease management.
|
| 305 |
+
self.drop(requests_completed)
|
| 306 |
+
|
| 307 |
+
# Retry on a separate thread so the dispatcher thread isn't blocked
|
| 308 |
+
# by sleeps.
|
| 309 |
+
if requests_to_retry:
|
| 310 |
+
self._start_retry_thread(
|
| 311 |
+
"Thread-RetryAcks",
|
| 312 |
+
functools.partial(self._retry_acks, requests_to_retry),
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
+
def _start_retry_thread(self, thread_name, thread_target):
|
| 316 |
+
# note: if the thread is *not* a daemon, a memory leak exists due to a cpython issue.
|
| 317 |
+
# https://github.com/googleapis/python-pubsub/issues/395#issuecomment-829910303
|
| 318 |
+
# https://github.com/googleapis/python-pubsub/issues/395#issuecomment-830092418
|
| 319 |
+
retry_thread = threading.Thread(
|
| 320 |
+
name=thread_name,
|
| 321 |
+
target=thread_target,
|
| 322 |
+
daemon=True,
|
| 323 |
+
)
|
| 324 |
+
# The thread finishes when the requests succeed or eventually fail with
|
| 325 |
+
# a back-end timeout error or other permanent failure.
|
| 326 |
+
retry_thread.start()
|
| 327 |
+
|
| 328 |
+
def _retry_acks(self, requests_to_retry: List[requests.AckRequest]):
|
| 329 |
+
retry_delay_gen = exponential_sleep_generator(
|
| 330 |
+
initial=_MIN_EXACTLY_ONCE_DELIVERY_ACK_MODACK_RETRY_DURATION_SECS,
|
| 331 |
+
maximum=_MAX_EXACTLY_ONCE_DELIVERY_ACK_MODACK_RETRY_DURATION_SECS,
|
| 332 |
+
)
|
| 333 |
+
while requests_to_retry:
|
| 334 |
+
time_to_wait = next(retry_delay_gen)
|
| 335 |
+
_LOGGER.debug(
|
| 336 |
+
"Retrying {len(requests_to_retry)} ack(s) after delay of "
|
| 337 |
+
+ str(time_to_wait)
|
| 338 |
+
+ " seconds"
|
| 339 |
+
)
|
| 340 |
+
time.sleep(time_to_wait)
|
| 341 |
+
|
| 342 |
+
ack_reqs_dict = {req.ack_id: req for req in requests_to_retry}
|
| 343 |
+
subscription_id: Optional[str] = None
|
| 344 |
+
project_id: Optional[str] = None
|
| 345 |
+
subscribe_links: List[trace.Link] = []
|
| 346 |
+
subscribe_spans: List[trace.Span] = []
|
| 347 |
+
for req in requests_to_retry:
|
| 348 |
+
if req.opentelemetry_data:
|
| 349 |
+
req.opentelemetry_data.add_subscribe_span_event("ack start")
|
| 350 |
+
if subscription_id is None:
|
| 351 |
+
subscription_id = req.opentelemetry_data.subscription_id
|
| 352 |
+
if project_id is None:
|
| 353 |
+
project_id = req.opentelemetry_data.project_id
|
| 354 |
+
subscribe_span: Optional[trace.Span] = (
|
| 355 |
+
req.opentelemetry_data.subscribe_span
|
| 356 |
+
)
|
| 357 |
+
if (
|
| 358 |
+
subscribe_span
|
| 359 |
+
and subscribe_span.get_span_context().trace_flags.sampled
|
| 360 |
+
):
|
| 361 |
+
subscribe_links.append(
|
| 362 |
+
trace.Link(subscribe_span.get_span_context())
|
| 363 |
+
)
|
| 364 |
+
subscribe_spans.append(subscribe_span)
|
| 365 |
+
ack_span: Optional[trace.Span] = None
|
| 366 |
+
if subscription_id and project_id:
|
| 367 |
+
ack_span = start_ack_span(
|
| 368 |
+
subscription_id,
|
| 369 |
+
len(ack_reqs_dict),
|
| 370 |
+
project_id,
|
| 371 |
+
subscribe_links,
|
| 372 |
+
)
|
| 373 |
+
if (
|
| 374 |
+
ack_span and ack_span.get_span_context().trace_flags.sampled
|
| 375 |
+
): # pragma: NO COVER
|
| 376 |
+
ack_span_context: trace.SpanContext = ack_span.get_span_context()
|
| 377 |
+
for subscribe_span in subscribe_spans:
|
| 378 |
+
subscribe_span.add_link(
|
| 379 |
+
context=ack_span_context,
|
| 380 |
+
attributes={
|
| 381 |
+
"messaging.operation.name": "ack",
|
| 382 |
+
},
|
| 383 |
+
)
|
| 384 |
+
|
| 385 |
+
requests_completed, requests_to_retry = self._manager.send_unary_ack(
|
| 386 |
+
ack_ids=[req.ack_id for req in requests_to_retry],
|
| 387 |
+
ack_reqs_dict=ack_reqs_dict,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
if ack_span:
|
| 391 |
+
ack_span.end()
|
| 392 |
+
|
| 393 |
+
for completed_ack in requests_completed:
|
| 394 |
+
if completed_ack.opentelemetry_data:
|
| 395 |
+
completed_ack.opentelemetry_data.add_subscribe_span_event("ack end")
|
| 396 |
+
completed_ack.opentelemetry_data.set_subscribe_span_result("acked")
|
| 397 |
+
completed_ack.opentelemetry_data.end_subscribe_span()
|
| 398 |
+
|
| 399 |
+
assert len(requests_to_retry) <= _ACK_IDS_BATCH_SIZE, (
|
| 400 |
+
"Too many requests to be retried."
|
| 401 |
+
)
|
| 402 |
+
# Remove the completed messages from lease management.
|
| 403 |
+
self.drop(requests_completed)
|
| 404 |
+
|
| 405 |
+
def drop(
|
| 406 |
+
self,
|
| 407 |
+
items: Sequence[
|
| 408 |
+
Union[requests.AckRequest, requests.DropRequest, requests.NackRequest]
|
| 409 |
+
],
|
| 410 |
+
) -> None:
|
| 411 |
+
"""Remove the given messages from lease management.
|
| 412 |
+
|
| 413 |
+
Args:
|
| 414 |
+
items: The items to drop.
|
| 415 |
+
"""
|
| 416 |
+
assert self._manager.leaser is not None
|
| 417 |
+
self._manager.leaser.remove(items)
|
| 418 |
+
ordering_keys = (k.ordering_key for k in items if k.ordering_key)
|
| 419 |
+
self._manager.activate_ordering_keys(ordering_keys)
|
| 420 |
+
self._manager.maybe_resume_consumer()
|
| 421 |
+
|
| 422 |
+
def lease(self, items: Sequence[requests.LeaseRequest]) -> None:
|
| 423 |
+
"""Add the given messages to lease management.
|
| 424 |
+
|
| 425 |
+
Args:
|
| 426 |
+
items: The items to lease.
|
| 427 |
+
"""
|
| 428 |
+
assert self._manager.leaser is not None
|
| 429 |
+
self._manager.leaser.add(items)
|
| 430 |
+
self._manager.maybe_pause_consumer()
|
| 431 |
+
|
| 432 |
+
def modify_ack_deadline(
|
| 433 |
+
self,
|
| 434 |
+
items: Sequence[requests.ModAckRequest],
|
| 435 |
+
default_deadline: Optional[float] = None,
|
| 436 |
+
) -> None:
|
| 437 |
+
"""Modify the ack deadline for the given messages.
|
| 438 |
+
|
| 439 |
+
Args:
|
| 440 |
+
items: The items to modify.
|
| 441 |
+
"""
|
| 442 |
+
# We must potentially split the request into multiple smaller requests
|
| 443 |
+
# to avoid the server-side max request size limit.
|
| 444 |
+
items_gen = iter(items)
|
| 445 |
+
ack_ids_gen = (item.ack_id for item in items)
|
| 446 |
+
deadline_seconds_gen = (item.seconds for item in items)
|
| 447 |
+
total_chunks = int(math.ceil(len(items) / _ACK_IDS_BATCH_SIZE))
|
| 448 |
+
|
| 449 |
+
subscription_id: Optional[str] = None
|
| 450 |
+
project_id: Optional[str] = None
|
| 451 |
+
|
| 452 |
+
for item in items:
|
| 453 |
+
if item.opentelemetry_data:
|
| 454 |
+
if math.isclose(item.seconds, 0):
|
| 455 |
+
item.opentelemetry_data.add_subscribe_span_event("nack start")
|
| 456 |
+
if subscription_id is None:
|
| 457 |
+
subscription_id = item.opentelemetry_data.subscription_id
|
| 458 |
+
if project_id is None:
|
| 459 |
+
project_id = item.opentelemetry_data.project_id
|
| 460 |
+
else:
|
| 461 |
+
item.opentelemetry_data.add_subscribe_span_event("modack start")
|
| 462 |
+
for _ in range(total_chunks):
|
| 463 |
+
ack_reqs_dict = {
|
| 464 |
+
req.ack_id: req
|
| 465 |
+
for req in itertools.islice(items_gen, _ACK_IDS_BATCH_SIZE)
|
| 466 |
+
}
|
| 467 |
+
subscribe_links: List[trace.Link] = []
|
| 468 |
+
subscribe_spans: List[trace.Span] = []
|
| 469 |
+
for ack_req in ack_reqs_dict.values():
|
| 470 |
+
if ack_req.opentelemetry_data and math.isclose(ack_req.seconds, 0):
|
| 471 |
+
subscribe_span: Optional[trace.Span] = (
|
| 472 |
+
ack_req.opentelemetry_data.subscribe_span
|
| 473 |
+
)
|
| 474 |
+
if (
|
| 475 |
+
subscribe_span
|
| 476 |
+
and subscribe_span.get_span_context().trace_flags.sampled
|
| 477 |
+
):
|
| 478 |
+
subscribe_links.append(
|
| 479 |
+
trace.Link(subscribe_span.get_span_context())
|
| 480 |
+
)
|
| 481 |
+
subscribe_spans.append(subscribe_span)
|
| 482 |
+
nack_span: Optional[trace.Span] = None
|
| 483 |
+
if subscription_id and project_id:
|
| 484 |
+
nack_span = start_nack_span(
|
| 485 |
+
subscription_id,
|
| 486 |
+
len(ack_reqs_dict),
|
| 487 |
+
project_id,
|
| 488 |
+
subscribe_links,
|
| 489 |
+
)
|
| 490 |
+
if (
|
| 491 |
+
nack_span and nack_span.get_span_context().trace_flags.sampled
|
| 492 |
+
): # pragma: NO COVER
|
| 493 |
+
nack_span_context: trace.SpanContext = nack_span.get_span_context()
|
| 494 |
+
for subscribe_span in subscribe_spans:
|
| 495 |
+
subscribe_span.add_link(
|
| 496 |
+
context=nack_span_context,
|
| 497 |
+
attributes={
|
| 498 |
+
"messaging.operation.name": "nack",
|
| 499 |
+
},
|
| 500 |
+
)
|
| 501 |
+
requests_to_retry: List[requests.ModAckRequest]
|
| 502 |
+
requests_completed: Optional[List[requests.ModAckRequest]] = None
|
| 503 |
+
if default_deadline is None:
|
| 504 |
+
# no further work needs to be done for `requests_to_retry`
|
| 505 |
+
requests_completed, requests_to_retry = self._manager.send_unary_modack(
|
| 506 |
+
modify_deadline_ack_ids=list(
|
| 507 |
+
itertools.islice(ack_ids_gen, _ACK_IDS_BATCH_SIZE)
|
| 508 |
+
),
|
| 509 |
+
modify_deadline_seconds=list(
|
| 510 |
+
itertools.islice(deadline_seconds_gen, _ACK_IDS_BATCH_SIZE)
|
| 511 |
+
),
|
| 512 |
+
ack_reqs_dict=ack_reqs_dict,
|
| 513 |
+
default_deadline=None,
|
| 514 |
+
)
|
| 515 |
+
else:
|
| 516 |
+
requests_completed, requests_to_retry = self._manager.send_unary_modack(
|
| 517 |
+
modify_deadline_ack_ids=itertools.islice(
|
| 518 |
+
ack_ids_gen, _ACK_IDS_BATCH_SIZE
|
| 519 |
+
),
|
| 520 |
+
modify_deadline_seconds=None,
|
| 521 |
+
ack_reqs_dict=ack_reqs_dict,
|
| 522 |
+
default_deadline=default_deadline,
|
| 523 |
+
)
|
| 524 |
+
if nack_span:
|
| 525 |
+
nack_span.end()
|
| 526 |
+
assert len(requests_to_retry) <= _ACK_IDS_BATCH_SIZE, (
|
| 527 |
+
"Too many requests to be retried."
|
| 528 |
+
)
|
| 529 |
+
|
| 530 |
+
for completed_modack in requests_completed:
|
| 531 |
+
if completed_modack.opentelemetry_data:
|
| 532 |
+
# nack is a modack with 0 extension seconds.
|
| 533 |
+
if math.isclose(completed_modack.seconds, 0):
|
| 534 |
+
completed_modack.opentelemetry_data.set_subscribe_span_result(
|
| 535 |
+
"nacked"
|
| 536 |
+
)
|
| 537 |
+
completed_modack.opentelemetry_data.add_subscribe_span_event(
|
| 538 |
+
"nack end"
|
| 539 |
+
)
|
| 540 |
+
completed_modack.opentelemetry_data.end_subscribe_span()
|
| 541 |
+
else:
|
| 542 |
+
completed_modack.opentelemetry_data.add_subscribe_span_event(
|
| 543 |
+
"modack end"
|
| 544 |
+
)
|
| 545 |
+
|
| 546 |
+
# Retry on a separate thread so the dispatcher thread isn't blocked
|
| 547 |
+
# by sleeps.
|
| 548 |
+
if requests_to_retry:
|
| 549 |
+
self._start_retry_thread(
|
| 550 |
+
"Thread-RetryModAcks",
|
| 551 |
+
functools.partial(self._retry_modacks, requests_to_retry),
|
| 552 |
+
)
|
| 553 |
+
|
| 554 |
+
def _retry_modacks(self, requests_to_retry):
|
| 555 |
+
retry_delay_gen = exponential_sleep_generator(
|
| 556 |
+
initial=_MIN_EXACTLY_ONCE_DELIVERY_ACK_MODACK_RETRY_DURATION_SECS,
|
| 557 |
+
maximum=_MAX_EXACTLY_ONCE_DELIVERY_ACK_MODACK_RETRY_DURATION_SECS,
|
| 558 |
+
)
|
| 559 |
+
while requests_to_retry:
|
| 560 |
+
time_to_wait = next(retry_delay_gen)
|
| 561 |
+
_LOGGER.debug(
|
| 562 |
+
"Retrying {len(requests_to_retry)} modack(s) after delay of "
|
| 563 |
+
+ str(time_to_wait)
|
| 564 |
+
+ " seconds"
|
| 565 |
+
)
|
| 566 |
+
time.sleep(time_to_wait)
|
| 567 |
+
|
| 568 |
+
ack_reqs_dict = {req.ack_id: req for req in requests_to_retry}
|
| 569 |
+
|
| 570 |
+
subscription_id = None
|
| 571 |
+
project_id = None
|
| 572 |
+
subscribe_links = []
|
| 573 |
+
subscribe_spans = []
|
| 574 |
+
for ack_req in ack_reqs_dict.values():
|
| 575 |
+
if ack_req.opentelemetry_data and math.isclose(ack_req.seconds, 0):
|
| 576 |
+
if subscription_id is None:
|
| 577 |
+
subscription_id = ack_req.opentelemetry_data.subscription_id
|
| 578 |
+
if project_id is None:
|
| 579 |
+
project_id = ack_req.opentelemetry_data.project_id
|
| 580 |
+
subscribe_span = ack_req.opentelemetry_data.subscribe_span
|
| 581 |
+
if (
|
| 582 |
+
subscribe_span
|
| 583 |
+
and subscribe_span.get_span_context().trace_flags.sampled
|
| 584 |
+
):
|
| 585 |
+
subscribe_links.append(
|
| 586 |
+
trace.Link(subscribe_span.get_span_context())
|
| 587 |
+
)
|
| 588 |
+
subscribe_spans.append(subscribe_span)
|
| 589 |
+
nack_span = None
|
| 590 |
+
if subscription_id and project_id:
|
| 591 |
+
nack_span = start_nack_span(
|
| 592 |
+
subscription_id,
|
| 593 |
+
len(ack_reqs_dict),
|
| 594 |
+
project_id,
|
| 595 |
+
subscribe_links,
|
| 596 |
+
)
|
| 597 |
+
if (
|
| 598 |
+
nack_span and nack_span.get_span_context().trace_flags.sampled
|
| 599 |
+
): # pragma: NO COVER
|
| 600 |
+
nack_span_context: trace.SpanContext = nack_span.get_span_context()
|
| 601 |
+
for subscribe_span in subscribe_spans:
|
| 602 |
+
subscribe_span.add_link(
|
| 603 |
+
context=nack_span_context,
|
| 604 |
+
attributes={
|
| 605 |
+
"messaging.operation.name": "nack",
|
| 606 |
+
},
|
| 607 |
+
)
|
| 608 |
+
requests_completed, requests_to_retry = self._manager.send_unary_modack(
|
| 609 |
+
modify_deadline_ack_ids=[req.ack_id for req in requests_to_retry],
|
| 610 |
+
modify_deadline_seconds=[req.seconds for req in requests_to_retry],
|
| 611 |
+
ack_reqs_dict=ack_reqs_dict,
|
| 612 |
+
)
|
| 613 |
+
if nack_span:
|
| 614 |
+
nack_span.end()
|
| 615 |
+
for completed_modack in requests_completed:
|
| 616 |
+
if completed_modack.opentelemetry_data:
|
| 617 |
+
# nack is a modack with 0 extension seconds.
|
| 618 |
+
if math.isclose(completed_modack.seconds, 0):
|
| 619 |
+
completed_modack.opentelemetry_data.set_subscribe_span_result(
|
| 620 |
+
"nacked"
|
| 621 |
+
)
|
| 622 |
+
completed_modack.opentelemetry_data.add_subscribe_span_event(
|
| 623 |
+
"nack end"
|
| 624 |
+
)
|
| 625 |
+
completed_modack.opentelemetry_data.end_subscribe_span()
|
| 626 |
+
else:
|
| 627 |
+
completed_modack.opentelemetry_data.add_subscribe_span_event(
|
| 628 |
+
"modack end"
|
| 629 |
+
)
|
| 630 |
+
|
| 631 |
+
def nack(self, items: Sequence[requests.NackRequest]) -> None:
|
| 632 |
+
"""Explicitly deny receipt of messages.
|
| 633 |
+
|
| 634 |
+
Args:
|
| 635 |
+
items: The items to deny.
|
| 636 |
+
"""
|
| 637 |
+
self.modify_ack_deadline(
|
| 638 |
+
[
|
| 639 |
+
requests.ModAckRequest(
|
| 640 |
+
ack_id=item.ack_id,
|
| 641 |
+
seconds=0,
|
| 642 |
+
future=item.future,
|
| 643 |
+
opentelemetry_data=item.opentelemetry_data,
|
| 644 |
+
)
|
| 645 |
+
for item in items
|
| 646 |
+
]
|
| 647 |
+
)
|
| 648 |
+
self.drop(
|
| 649 |
+
[
|
| 650 |
+
requests.DropRequest(
|
| 651 |
+
ack_id=item.ack_id,
|
| 652 |
+
byte_size=item.byte_size,
|
| 653 |
+
ordering_key=item.ordering_key,
|
| 654 |
+
)
|
| 655 |
+
for item in items
|
| 656 |
+
]
|
| 657 |
+
)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/heartbeater.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
import logging
|
| 18 |
+
import threading
|
| 19 |
+
import typing
|
| 20 |
+
from typing import Optional
|
| 21 |
+
|
| 22 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 23 |
+
from google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager import (
|
| 24 |
+
StreamingPullManager,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
_LOGGER = logging.getLogger(__name__)
|
| 29 |
+
_HEARTBEAT_WORKER_NAME = "Thread-Heartbeater"
|
| 30 |
+
# How often to send heartbeats in seconds. Determined as half the period of
|
| 31 |
+
# time where the Pub/Sub server will close the stream as inactive, which is
|
| 32 |
+
# 60 seconds.
|
| 33 |
+
_DEFAULT_PERIOD = 30
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class Heartbeater(object):
|
| 37 |
+
def __init__(self, manager: "StreamingPullManager", period: int = _DEFAULT_PERIOD):
|
| 38 |
+
self._thread: Optional[threading.Thread] = None
|
| 39 |
+
self._operational_lock = threading.Lock()
|
| 40 |
+
self._manager = manager
|
| 41 |
+
self._stop_event = threading.Event()
|
| 42 |
+
self._period = period
|
| 43 |
+
|
| 44 |
+
def heartbeat(self) -> None:
|
| 45 |
+
"""Periodically send streaming pull heartbeats."""
|
| 46 |
+
while not self._stop_event.is_set():
|
| 47 |
+
if self._manager.heartbeat():
|
| 48 |
+
_LOGGER.debug("Sent heartbeat.")
|
| 49 |
+
self._stop_event.wait(timeout=self._period)
|
| 50 |
+
|
| 51 |
+
_LOGGER.debug("%s exiting.", _HEARTBEAT_WORKER_NAME)
|
| 52 |
+
|
| 53 |
+
def start(self) -> None:
|
| 54 |
+
with self._operational_lock:
|
| 55 |
+
if self._thread is not None:
|
| 56 |
+
raise ValueError("Heartbeater is already running.")
|
| 57 |
+
|
| 58 |
+
# Create and start the helper thread.
|
| 59 |
+
self._stop_event.clear()
|
| 60 |
+
thread = threading.Thread(
|
| 61 |
+
name=_HEARTBEAT_WORKER_NAME, target=self.heartbeat
|
| 62 |
+
)
|
| 63 |
+
thread.daemon = True
|
| 64 |
+
thread.start()
|
| 65 |
+
_LOGGER.debug("Started helper thread %s", thread.name)
|
| 66 |
+
self._thread = thread
|
| 67 |
+
|
| 68 |
+
def stop(self) -> None:
|
| 69 |
+
with self._operational_lock:
|
| 70 |
+
self._stop_event.set()
|
| 71 |
+
|
| 72 |
+
if self._thread is not None:
|
| 73 |
+
# The thread should automatically exit when the consumer is
|
| 74 |
+
# inactive.
|
| 75 |
+
self._thread.join()
|
| 76 |
+
|
| 77 |
+
self._thread = None
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/helper_threads.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import logging
|
| 16 |
+
import queue
|
| 17 |
+
import time
|
| 18 |
+
import uuid
|
| 19 |
+
from typing import Any, Callable, List, Optional, Sequence
|
| 20 |
+
|
| 21 |
+
__all__ = ("QueueCallbackWorker", "STOP")
|
| 22 |
+
|
| 23 |
+
_LOGGER = logging.getLogger(__name__)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Helper thread stop indicator. This could be a sentinel object or None,
|
| 27 |
+
# but the sentinel object's ID can change if the process is forked, and
|
| 28 |
+
# None has the possibility of a user accidentally killing the helper
|
| 29 |
+
# thread.
|
| 30 |
+
STOP = uuid.uuid4()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _get_many(
|
| 34 |
+
queue_: queue.Queue, max_items: Optional[int] = None, max_latency: float = 0
|
| 35 |
+
) -> List[Any]:
|
| 36 |
+
"""Get multiple items from a Queue.
|
| 37 |
+
|
| 38 |
+
Gets at least one (blocking) and at most ``max_items`` items
|
| 39 |
+
(non-blocking) from a given Queue. Does not mark the items as done.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
queue_: The Queue to get items from.
|
| 43 |
+
max_items:
|
| 44 |
+
The maximum number of items to get. If ``None``, then all available items
|
| 45 |
+
in the queue are returned.
|
| 46 |
+
max_latency:
|
| 47 |
+
The maximum number of seconds to wait for more than one item from a queue.
|
| 48 |
+
This number includes the time required to retrieve the first item.
|
| 49 |
+
|
| 50 |
+
Returns:
|
| 51 |
+
A sequence of items retrieved from the queue.
|
| 52 |
+
"""
|
| 53 |
+
start = time.time()
|
| 54 |
+
# Always return at least one item.
|
| 55 |
+
items = [queue_.get()]
|
| 56 |
+
while max_items is None or len(items) < max_items:
|
| 57 |
+
try:
|
| 58 |
+
elapsed = time.time() - start
|
| 59 |
+
timeout = max(0, max_latency - elapsed)
|
| 60 |
+
items.append(queue_.get(timeout=timeout))
|
| 61 |
+
except queue.Empty:
|
| 62 |
+
break
|
| 63 |
+
return items
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class QueueCallbackWorker(object):
|
| 67 |
+
"""A helper that executes a callback for items sent in a queue.
|
| 68 |
+
|
| 69 |
+
Calls a blocking ``get()`` on the ``queue`` until it encounters
|
| 70 |
+
:attr:`STOP`.
|
| 71 |
+
|
| 72 |
+
Args:
|
| 73 |
+
queue:
|
| 74 |
+
A Queue instance, appropriate for crossing the concurrency boundary
|
| 75 |
+
implemented by ``executor``. Items will be popped off (with a blocking
|
| 76 |
+
``get()``) until :attr:`STOP` is encountered.
|
| 77 |
+
callback:
|
| 78 |
+
A callback that can process items pulled off of the queue. Multiple items
|
| 79 |
+
will be passed to the callback in batches.
|
| 80 |
+
max_items:
|
| 81 |
+
The maximum amount of items that will be passed to the callback at a time.
|
| 82 |
+
max_latency:
|
| 83 |
+
The maximum amount of time in seconds to wait for additional items before
|
| 84 |
+
executing the callback.
|
| 85 |
+
"""
|
| 86 |
+
|
| 87 |
+
def __init__(
|
| 88 |
+
self,
|
| 89 |
+
queue: queue.Queue,
|
| 90 |
+
callback: Callable[[Sequence[Any]], Any],
|
| 91 |
+
max_items: int = 100,
|
| 92 |
+
max_latency: float = 0,
|
| 93 |
+
):
|
| 94 |
+
self.queue = queue
|
| 95 |
+
self._callback = callback
|
| 96 |
+
self.max_items = max_items
|
| 97 |
+
self.max_latency = max_latency
|
| 98 |
+
|
| 99 |
+
def __call__(self) -> None:
|
| 100 |
+
continue_ = True
|
| 101 |
+
while continue_:
|
| 102 |
+
items = _get_many(
|
| 103 |
+
self.queue, max_items=self.max_items, max_latency=self.max_latency
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# If stop is in the items, process all items up to STOP and then
|
| 107 |
+
# exit.
|
| 108 |
+
try:
|
| 109 |
+
items = items[: items.index(STOP)]
|
| 110 |
+
continue_ = False
|
| 111 |
+
except ValueError:
|
| 112 |
+
pass
|
| 113 |
+
|
| 114 |
+
# Run the callback. If any exceptions occur, log them and
|
| 115 |
+
# continue.
|
| 116 |
+
try:
|
| 117 |
+
self._callback(items)
|
| 118 |
+
except Exception as exc:
|
| 119 |
+
_LOGGER.exception("Error in queue callback worker: %s", exc)
|
| 120 |
+
|
| 121 |
+
_LOGGER.debug("Exiting the QueueCallbackWorker.")
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/histogram.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from typing import Dict, Optional, Union
|
| 16 |
+
|
| 17 |
+
MIN_ACK_DEADLINE = 10
|
| 18 |
+
MAX_ACK_DEADLINE = 600
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class Histogram(object):
|
| 22 |
+
"""Representation of a single histogram.
|
| 23 |
+
|
| 24 |
+
The purpose of this class is to store actual ack timing information
|
| 25 |
+
in order to predict how long to renew leases.
|
| 26 |
+
|
| 27 |
+
The default implementation uses the 99th percentile of previous ack
|
| 28 |
+
times to implicitly lease messages; however, custom
|
| 29 |
+
:class:`~.pubsub_v1.subscriber._consumer.Consumer` subclasses
|
| 30 |
+
are free to use a different formula.
|
| 31 |
+
|
| 32 |
+
The precision of data stored is to the nearest integer. Additionally,
|
| 33 |
+
values outside the range of ``MIN_ACK_DEADLINE <= x <= MAX_ACK_DEADLINE`` are stored
|
| 34 |
+
as ``MIN_ACK_DEADLINE`` or ``MAX_ACK_DEADLINE``, since these are the boundaries of
|
| 35 |
+
leases in the actual API.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
def __init__(self, data: Optional[Dict[int, int]] = None):
|
| 39 |
+
"""Instantiate the histogram.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
data:
|
| 43 |
+
The data strucure to be used to store the underlying data. The default
|
| 44 |
+
is an empty dictionary. This can be set to a dictionary-like object if
|
| 45 |
+
required (for example, if a special object is needed for concurrency
|
| 46 |
+
reasons).
|
| 47 |
+
"""
|
| 48 |
+
# The data is stored as a dictionary, with the keys being the
|
| 49 |
+
# value being added and the values being the number of times that
|
| 50 |
+
# value was added to the dictionary.
|
| 51 |
+
#
|
| 52 |
+
# This is depending on the Python interpreter's implicit ordering
|
| 53 |
+
# of dictionaries, which is a bitwise sort by the key's ``hash()``
|
| 54 |
+
# value. Because ``hash(int i) -> i`` and all of our keys are
|
| 55 |
+
# positive integers (negatives would be a problem because the sort
|
| 56 |
+
# is bitwise), we can rely on this.
|
| 57 |
+
if data is None:
|
| 58 |
+
data = {}
|
| 59 |
+
self._data = data
|
| 60 |
+
self._len = 0
|
| 61 |
+
|
| 62 |
+
def __len__(self) -> int:
|
| 63 |
+
"""Return the total number of data points in this histogram.
|
| 64 |
+
|
| 65 |
+
This is cached on a separate counter (rather than computing it using
|
| 66 |
+
``sum([v for v in self._data.values()])``) to optimize lookup.
|
| 67 |
+
|
| 68 |
+
Returns:
|
| 69 |
+
The total number of data points in this histogram.
|
| 70 |
+
"""
|
| 71 |
+
return self._len
|
| 72 |
+
|
| 73 |
+
def __contains__(self, needle: int) -> bool:
|
| 74 |
+
"""Return ``True`` if needle is present in the histogram, ``False`` otherwise."""
|
| 75 |
+
return needle in self._data
|
| 76 |
+
|
| 77 |
+
def __repr__(self):
|
| 78 |
+
return "<Histogram: {len} values between {min} and {max}>".format(
|
| 79 |
+
len=len(self), max=self.max, min=self.min
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
@property
|
| 83 |
+
def max(self) -> int:
|
| 84 |
+
"""Return the maximum value in this histogram.
|
| 85 |
+
|
| 86 |
+
If there are no values in the histogram at all, return ``MAX_ACK_DEADLINE``.
|
| 87 |
+
|
| 88 |
+
Returns:
|
| 89 |
+
The maximum value in the histogram.
|
| 90 |
+
"""
|
| 91 |
+
if len(self._data) == 0:
|
| 92 |
+
return MAX_ACK_DEADLINE
|
| 93 |
+
return next(iter(reversed(sorted(self._data.keys()))))
|
| 94 |
+
|
| 95 |
+
@property
|
| 96 |
+
def min(self) -> int:
|
| 97 |
+
"""Return the minimum value in this histogram.
|
| 98 |
+
|
| 99 |
+
If there are no values in the histogram at all, return ``MIN_ACK_DEADLINE``.
|
| 100 |
+
|
| 101 |
+
Returns:
|
| 102 |
+
The minimum value in the histogram.
|
| 103 |
+
"""
|
| 104 |
+
if len(self._data) == 0:
|
| 105 |
+
return MIN_ACK_DEADLINE
|
| 106 |
+
return next(iter(sorted(self._data.keys())))
|
| 107 |
+
|
| 108 |
+
def add(self, value: Union[int, float]) -> None:
|
| 109 |
+
"""Add the value to this histogram.
|
| 110 |
+
|
| 111 |
+
Args:
|
| 112 |
+
value:
|
| 113 |
+
The value. Values outside of
|
| 114 |
+
``MIN_ACK_DEADLINE <= x <= MAX_ACK_DEADLINE``
|
| 115 |
+
will be raised to ``MIN_ACK_DEADLINE`` or reduced to
|
| 116 |
+
``MAX_ACK_DEADLINE``.
|
| 117 |
+
"""
|
| 118 |
+
# If the value is out of bounds, bring it in bounds.
|
| 119 |
+
value = int(value)
|
| 120 |
+
if value < MIN_ACK_DEADLINE:
|
| 121 |
+
value = MIN_ACK_DEADLINE
|
| 122 |
+
elif value > MAX_ACK_DEADLINE:
|
| 123 |
+
value = MAX_ACK_DEADLINE
|
| 124 |
+
|
| 125 |
+
# Add the value to the histogram's data dictionary.
|
| 126 |
+
self._data.setdefault(value, 0)
|
| 127 |
+
self._data[value] += 1
|
| 128 |
+
self._len += 1
|
| 129 |
+
|
| 130 |
+
def percentile(self, percent: Union[int, float]) -> int:
|
| 131 |
+
"""Return the value that is the Nth precentile in the histogram.
|
| 132 |
+
|
| 133 |
+
Args:
|
| 134 |
+
percent:
|
| 135 |
+
The precentile being sought. The default consumer implementations
|
| 136 |
+
consistently use ``99``.
|
| 137 |
+
|
| 138 |
+
Returns:
|
| 139 |
+
The value corresponding to the requested percentile.
|
| 140 |
+
"""
|
| 141 |
+
# Sanity check: Any value over 100 should become 100.
|
| 142 |
+
if percent >= 100:
|
| 143 |
+
percent = 100
|
| 144 |
+
|
| 145 |
+
# Determine the actual target number.
|
| 146 |
+
target = len(self) - len(self) * (percent / 100)
|
| 147 |
+
|
| 148 |
+
# Iterate over the values in reverse, dropping the target by the
|
| 149 |
+
# number of times each value has been seen. When the target passes
|
| 150 |
+
# 0, return the value we are currently viewing.
|
| 151 |
+
for k in reversed(sorted(self._data.keys())):
|
| 152 |
+
target -= self._data[k]
|
| 153 |
+
if target < 0:
|
| 154 |
+
return k
|
| 155 |
+
|
| 156 |
+
# The only way to get here is if there was no data.
|
| 157 |
+
# In this case, just return the shortest possible deadline.
|
| 158 |
+
return MIN_ACK_DEADLINE
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/leaser.py
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
import copy
|
| 18 |
+
import logging
|
| 19 |
+
import random
|
| 20 |
+
import threading
|
| 21 |
+
import time
|
| 22 |
+
import typing
|
| 23 |
+
from typing import Dict, Iterable, Optional, Union
|
| 24 |
+
|
| 25 |
+
from google.cloud.pubsub_v1.open_telemetry.subscribe_opentelemetry import (
|
| 26 |
+
SubscribeOpenTelemetry,
|
| 27 |
+
)
|
| 28 |
+
from google.cloud.pubsub_v1.subscriber._protocol.dispatcher import _MAX_BATCH_LATENCY
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
from collections.abc import KeysView
|
| 32 |
+
|
| 33 |
+
KeysView[None] # KeysView is only subscriptable in Python 3.9+
|
| 34 |
+
except TypeError:
|
| 35 |
+
# Deprecated since Python 3.9, thus only use as a fallback in older Python versions
|
| 36 |
+
from typing import KeysView
|
| 37 |
+
|
| 38 |
+
from google.cloud.pubsub_v1.subscriber._protocol import requests
|
| 39 |
+
|
| 40 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 41 |
+
from google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager import (
|
| 42 |
+
StreamingPullManager,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
_LOGGER = logging.getLogger(__name__)
|
| 47 |
+
_LEASE_WORKER_NAME = "Thread-LeaseMaintainer"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class _LeasedMessage(typing.NamedTuple):
|
| 51 |
+
sent_time: float
|
| 52 |
+
"""The local time when ACK ID was initially leased in seconds since the epoch."""
|
| 53 |
+
|
| 54 |
+
size: int
|
| 55 |
+
ordering_key: Optional[str]
|
| 56 |
+
opentelemetry_data: Optional[SubscribeOpenTelemetry]
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class Leaser(object):
|
| 60 |
+
def __init__(self, manager: "StreamingPullManager"):
|
| 61 |
+
self._thread: Optional[threading.Thread] = None
|
| 62 |
+
self._manager = manager
|
| 63 |
+
|
| 64 |
+
# a lock used for start/stop operations, protecting the _thread attribute
|
| 65 |
+
self._operational_lock = threading.Lock()
|
| 66 |
+
|
| 67 |
+
# A lock ensuring that add/remove operations are atomic and cannot be
|
| 68 |
+
# intertwined. Protects the _leased_messages and _bytes attributes.
|
| 69 |
+
self._add_remove_lock = threading.Lock()
|
| 70 |
+
|
| 71 |
+
# Dict of ack_id -> _LeasedMessage
|
| 72 |
+
self._leased_messages: Dict[str, _LeasedMessage] = {}
|
| 73 |
+
|
| 74 |
+
self._bytes = 0
|
| 75 |
+
"""The total number of bytes consumed by leased messages."""
|
| 76 |
+
|
| 77 |
+
self._stop_event = threading.Event()
|
| 78 |
+
|
| 79 |
+
@property
|
| 80 |
+
def message_count(self) -> int:
|
| 81 |
+
"""The number of leased messages."""
|
| 82 |
+
return len(self._leased_messages)
|
| 83 |
+
|
| 84 |
+
@property
|
| 85 |
+
def ack_ids(self) -> KeysView[str]:
|
| 86 |
+
"""The ack IDs of all leased messages."""
|
| 87 |
+
return self._leased_messages.keys()
|
| 88 |
+
|
| 89 |
+
@property
|
| 90 |
+
def bytes(self) -> int:
|
| 91 |
+
"""The total size, in bytes, of all leased messages."""
|
| 92 |
+
return self._bytes
|
| 93 |
+
|
| 94 |
+
def add(self, items: Iterable[requests.LeaseRequest]) -> None:
|
| 95 |
+
"""Add messages to be managed by the leaser."""
|
| 96 |
+
with self._add_remove_lock:
|
| 97 |
+
for item in items:
|
| 98 |
+
# Add the ack ID to the set of managed ack IDs, and increment
|
| 99 |
+
# the size counter.
|
| 100 |
+
if item.ack_id not in self._leased_messages:
|
| 101 |
+
self._leased_messages[item.ack_id] = _LeasedMessage(
|
| 102 |
+
sent_time=float("inf"),
|
| 103 |
+
size=item.byte_size,
|
| 104 |
+
ordering_key=item.ordering_key,
|
| 105 |
+
opentelemetry_data=item.opentelemetry_data,
|
| 106 |
+
)
|
| 107 |
+
self._bytes += item.byte_size
|
| 108 |
+
else:
|
| 109 |
+
_LOGGER.debug("Message %s is already lease managed", item.ack_id)
|
| 110 |
+
|
| 111 |
+
def start_lease_expiry_timer(self, ack_ids: Iterable[str]) -> None:
|
| 112 |
+
"""Start the lease expiry timer for `items`.
|
| 113 |
+
|
| 114 |
+
Args:
|
| 115 |
+
items: Sequence of ack-ids for which to start lease expiry timers.
|
| 116 |
+
"""
|
| 117 |
+
with self._add_remove_lock:
|
| 118 |
+
for ack_id in ack_ids:
|
| 119 |
+
lease_info = self._leased_messages.get(ack_id)
|
| 120 |
+
# Lease info might not exist for this ack_id because it has already
|
| 121 |
+
# been removed by remove().
|
| 122 |
+
if lease_info:
|
| 123 |
+
self._leased_messages[ack_id] = lease_info._replace(
|
| 124 |
+
sent_time=time.time()
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
def remove(
|
| 128 |
+
self,
|
| 129 |
+
items: Iterable[
|
| 130 |
+
Union[requests.AckRequest, requests.DropRequest, requests.NackRequest]
|
| 131 |
+
],
|
| 132 |
+
) -> None:
|
| 133 |
+
"""Remove messages from lease management."""
|
| 134 |
+
with self._add_remove_lock:
|
| 135 |
+
# Remove the ack ID from lease management, and decrement the
|
| 136 |
+
# byte counter.
|
| 137 |
+
for item in items:
|
| 138 |
+
if self._leased_messages.pop(item.ack_id, None) is not None:
|
| 139 |
+
self._bytes -= item.byte_size
|
| 140 |
+
else:
|
| 141 |
+
_LOGGER.debug("Item %s was not managed.", item.ack_id)
|
| 142 |
+
|
| 143 |
+
if self._bytes < 0:
|
| 144 |
+
_LOGGER.debug("Bytes was unexpectedly negative: %d", self._bytes)
|
| 145 |
+
self._bytes = 0
|
| 146 |
+
|
| 147 |
+
def maintain_leases(self) -> None:
|
| 148 |
+
"""Maintain all of the leases being managed.
|
| 149 |
+
|
| 150 |
+
This method modifies the ack deadline for all of the managed
|
| 151 |
+
ack IDs, then waits for most of that time (but with jitter), and
|
| 152 |
+
repeats.
|
| 153 |
+
"""
|
| 154 |
+
while not self._stop_event.is_set():
|
| 155 |
+
# Determine the appropriate duration for the lease. This is
|
| 156 |
+
# based off of how long previous messages have taken to ack, with
|
| 157 |
+
# a sensible default and within the ranges allowed by Pub/Sub.
|
| 158 |
+
# Also update the deadline currently used if enough new ACK data has been
|
| 159 |
+
# gathered since the last deadline update.
|
| 160 |
+
deadline = self._manager._obtain_ack_deadline(maybe_update=True)
|
| 161 |
+
_LOGGER.debug("The current deadline value is %d seconds.", deadline)
|
| 162 |
+
|
| 163 |
+
# Make a copy of the leased messages. This is needed because it's
|
| 164 |
+
# possible for another thread to modify the dictionary while
|
| 165 |
+
# we're iterating over it.
|
| 166 |
+
leased_messages = copy.copy(self._leased_messages)
|
| 167 |
+
|
| 168 |
+
# Drop any leases that are beyond the max lease time. This ensures
|
| 169 |
+
# that in the event of a badly behaving actor, we can drop messages
|
| 170 |
+
# and allow the Pub/Sub server to resend them.
|
| 171 |
+
cutoff = time.time() - self._manager.flow_control.max_lease_duration
|
| 172 |
+
to_drop = [
|
| 173 |
+
requests.DropRequest(ack_id, item.size, item.ordering_key)
|
| 174 |
+
for ack_id, item in leased_messages.items()
|
| 175 |
+
if item.sent_time < cutoff
|
| 176 |
+
]
|
| 177 |
+
|
| 178 |
+
if to_drop:
|
| 179 |
+
_LOGGER.warning(
|
| 180 |
+
"Dropping %s items because they were leased too long.", len(to_drop)
|
| 181 |
+
)
|
| 182 |
+
assert self._manager.dispatcher is not None
|
| 183 |
+
for drop_msg in to_drop:
|
| 184 |
+
leased_message = leased_messages.get(drop_msg.ack_id)
|
| 185 |
+
if leased_message and leased_message.opentelemetry_data:
|
| 186 |
+
leased_message.opentelemetry_data.add_process_span_event(
|
| 187 |
+
"expired"
|
| 188 |
+
)
|
| 189 |
+
leased_message.opentelemetry_data.end_process_span()
|
| 190 |
+
leased_message.opentelemetry_data.set_subscribe_span_result(
|
| 191 |
+
"expired"
|
| 192 |
+
)
|
| 193 |
+
leased_message.opentelemetry_data.end_subscribe_span()
|
| 194 |
+
self._manager.dispatcher.drop(to_drop)
|
| 195 |
+
|
| 196 |
+
# Remove dropped items from our copy of the leased messages (they
|
| 197 |
+
# have already been removed from the real one by
|
| 198 |
+
# self._manager.drop(), which calls self.remove()).
|
| 199 |
+
for item in to_drop:
|
| 200 |
+
leased_messages.pop(item.ack_id)
|
| 201 |
+
|
| 202 |
+
# Create a modack request.
|
| 203 |
+
# We do not actually call `modify_ack_deadline` over and over
|
| 204 |
+
# because it is more efficient to make a single request.
|
| 205 |
+
ack_ids = leased_messages.keys()
|
| 206 |
+
expired_ack_ids = set()
|
| 207 |
+
if ack_ids:
|
| 208 |
+
_LOGGER.debug("Renewing lease for %d ack IDs.", len(ack_ids))
|
| 209 |
+
|
| 210 |
+
# NOTE: This may not work as expected if ``consumer.active``
|
| 211 |
+
# has changed since we checked it. An implementation
|
| 212 |
+
# without any sort of race condition would require a
|
| 213 |
+
# way for ``send_request`` to fail when the consumer
|
| 214 |
+
# is inactive.
|
| 215 |
+
assert self._manager.dispatcher is not None
|
| 216 |
+
ack_id_gen = (ack_id for ack_id in ack_ids)
|
| 217 |
+
opentelemetry_data = [
|
| 218 |
+
message.opentelemetry_data
|
| 219 |
+
for message in list(leased_messages.values())
|
| 220 |
+
if message.opentelemetry_data
|
| 221 |
+
]
|
| 222 |
+
expired_ack_ids = self._manager._send_lease_modacks(
|
| 223 |
+
ack_id_gen,
|
| 224 |
+
deadline,
|
| 225 |
+
opentelemetry_data,
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
start_time = time.time()
|
| 229 |
+
# If exactly once delivery is enabled, we should drop all expired ack_ids from lease management.
|
| 230 |
+
if self._manager._exactly_once_delivery_enabled() and len(expired_ack_ids):
|
| 231 |
+
assert self._manager.dispatcher is not None
|
| 232 |
+
for ack_id in expired_ack_ids:
|
| 233 |
+
msg = leased_messages.get(ack_id)
|
| 234 |
+
if msg and msg.opentelemetry_data:
|
| 235 |
+
msg.opentelemetry_data.add_process_span_event("expired")
|
| 236 |
+
msg.opentelemetry_data.end_process_span()
|
| 237 |
+
msg.opentelemetry_data.set_subscribe_span_result("expired")
|
| 238 |
+
msg.opentelemetry_data.end_subscribe_span()
|
| 239 |
+
self._manager.dispatcher.drop(
|
| 240 |
+
[
|
| 241 |
+
requests.DropRequest(
|
| 242 |
+
ack_id,
|
| 243 |
+
leased_messages.get(ack_id).size, # type: ignore
|
| 244 |
+
leased_messages.get(ack_id).ordering_key, # type: ignore
|
| 245 |
+
)
|
| 246 |
+
for ack_id in expired_ack_ids
|
| 247 |
+
if ack_id in leased_messages
|
| 248 |
+
]
|
| 249 |
+
)
|
| 250 |
+
# Now wait an appropriate period of time and do this again.
|
| 251 |
+
#
|
| 252 |
+
# We determine the appropriate period of time based on a random
|
| 253 |
+
# period between:
|
| 254 |
+
# minimum: MAX_BATCH_LATENCY (to prevent duplicate modacks being created in one batch)
|
| 255 |
+
# maximum: 90% of the deadline
|
| 256 |
+
# This maximum time attempts to prevent ack expiration before new lease modacks arrive at the server.
|
| 257 |
+
# This use of jitter (http://bit.ly/2s2ekL7) helps decrease contention in cases
|
| 258 |
+
# where there are many clients.
|
| 259 |
+
# If we spent any time iterating over expired acks, we should subtract this from the deadline.
|
| 260 |
+
snooze = random.uniform(
|
| 261 |
+
_MAX_BATCH_LATENCY, (deadline * 0.9 - (time.time() - start_time))
|
| 262 |
+
)
|
| 263 |
+
_LOGGER.debug("Snoozing lease management for %f seconds.", snooze)
|
| 264 |
+
self._stop_event.wait(timeout=snooze)
|
| 265 |
+
|
| 266 |
+
_LOGGER.debug("%s exiting.", _LEASE_WORKER_NAME)
|
| 267 |
+
|
| 268 |
+
def start(self) -> None:
|
| 269 |
+
with self._operational_lock:
|
| 270 |
+
if self._thread is not None:
|
| 271 |
+
raise ValueError("Leaser is already running.")
|
| 272 |
+
|
| 273 |
+
# Create and start the helper thread.
|
| 274 |
+
self._stop_event.clear()
|
| 275 |
+
thread = threading.Thread(
|
| 276 |
+
name=_LEASE_WORKER_NAME, target=self.maintain_leases
|
| 277 |
+
)
|
| 278 |
+
thread.daemon = True
|
| 279 |
+
thread.start()
|
| 280 |
+
_LOGGER.debug("Started helper thread %s", thread.name)
|
| 281 |
+
self._thread = thread
|
| 282 |
+
|
| 283 |
+
def stop(self) -> None:
|
| 284 |
+
with self._operational_lock:
|
| 285 |
+
self._stop_event.set()
|
| 286 |
+
|
| 287 |
+
if self._thread is not None:
|
| 288 |
+
# The thread should automatically exit when the consumer is
|
| 289 |
+
# inactive.
|
| 290 |
+
self._thread.join()
|
| 291 |
+
|
| 292 |
+
self._thread = None
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/messages_on_hold.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import collections
|
| 16 |
+
import logging
|
| 17 |
+
import typing
|
| 18 |
+
from typing import Any, Callable, Iterable, Optional
|
| 19 |
+
|
| 20 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 21 |
+
from google.cloud.pubsub_v1 import subscriber
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
_LOGGER = logging.getLogger(__name__)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class MessagesOnHold(object):
|
| 28 |
+
"""Tracks messages on hold by ordering key. Not thread-safe."""
|
| 29 |
+
|
| 30 |
+
def __init__(self):
|
| 31 |
+
self._size = 0
|
| 32 |
+
|
| 33 |
+
# A FIFO queue for the messages that have been received from the server,
|
| 34 |
+
# but not yet sent to the user callback.
|
| 35 |
+
# Both ordered and unordered messages may be in this queue. Ordered
|
| 36 |
+
# message state tracked in _pending_ordered_messages once ordered
|
| 37 |
+
# messages are taken off this queue.
|
| 38 |
+
# The tail of the queue is to the right side of the deque; the head is
|
| 39 |
+
# to the left side.
|
| 40 |
+
self._messages_on_hold = collections.deque()
|
| 41 |
+
|
| 42 |
+
# Dict of ordering_key -> queue of ordered messages that have not been
|
| 43 |
+
# delivered to the user.
|
| 44 |
+
# All ordering keys in this collection have a message in flight. Once
|
| 45 |
+
# that one is acked or nacked, the next message in the queue for that
|
| 46 |
+
# ordering key will be sent.
|
| 47 |
+
# If the queue is empty, it means there's a message for that key in
|
| 48 |
+
# flight, but there are no pending messages.
|
| 49 |
+
self._pending_ordered_messages = {}
|
| 50 |
+
|
| 51 |
+
@property
|
| 52 |
+
def size(self) -> int:
|
| 53 |
+
"""Return the number of messages on hold across ordered and unordered messages.
|
| 54 |
+
|
| 55 |
+
Note that this object may still store information about ordered messages
|
| 56 |
+
in flight even if size is zero.
|
| 57 |
+
|
| 58 |
+
Returns:
|
| 59 |
+
The size value.
|
| 60 |
+
"""
|
| 61 |
+
return self._size
|
| 62 |
+
|
| 63 |
+
def get(self) -> Optional["subscriber.message.Message"]:
|
| 64 |
+
"""Gets a message from the on-hold queue. A message with an ordering
|
| 65 |
+
key wont be returned if there's another message with the same key in
|
| 66 |
+
flight.
|
| 67 |
+
|
| 68 |
+
Returns:
|
| 69 |
+
A message that hasn't been sent to the user yet or ``None`` if there are no
|
| 70 |
+
messages available.
|
| 71 |
+
"""
|
| 72 |
+
while self._messages_on_hold:
|
| 73 |
+
msg = self._messages_on_hold.popleft()
|
| 74 |
+
|
| 75 |
+
if msg.ordering_key:
|
| 76 |
+
pending_queue = self._pending_ordered_messages.get(msg.ordering_key)
|
| 77 |
+
if pending_queue is None:
|
| 78 |
+
# Create empty queue to indicate a message with the
|
| 79 |
+
# ordering key is in flight.
|
| 80 |
+
self._pending_ordered_messages[msg.ordering_key] = (
|
| 81 |
+
collections.deque()
|
| 82 |
+
)
|
| 83 |
+
self._size = self._size - 1
|
| 84 |
+
return msg
|
| 85 |
+
else:
|
| 86 |
+
# Another message is in flight so add message to end of
|
| 87 |
+
# queue for this ordering key.
|
| 88 |
+
pending_queue.append(msg)
|
| 89 |
+
else:
|
| 90 |
+
# Unordered messages can be returned without any
|
| 91 |
+
# restrictions.
|
| 92 |
+
self._size = self._size - 1
|
| 93 |
+
return msg
|
| 94 |
+
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
def put(self, message: "subscriber.message.Message") -> None:
|
| 98 |
+
"""Put a message on hold.
|
| 99 |
+
|
| 100 |
+
Args:
|
| 101 |
+
message: The message to put on hold.
|
| 102 |
+
"""
|
| 103 |
+
if message.opentelemetry_data:
|
| 104 |
+
message.opentelemetry_data.start_subscribe_scheduler_span()
|
| 105 |
+
self._messages_on_hold.append(message)
|
| 106 |
+
self._size = self._size + 1
|
| 107 |
+
|
| 108 |
+
def activate_ordering_keys(
|
| 109 |
+
self,
|
| 110 |
+
ordering_keys: Iterable[str],
|
| 111 |
+
schedule_message_callback: Callable[["subscriber.message.Message"], Any],
|
| 112 |
+
) -> None:
|
| 113 |
+
"""Send the next message in the queue for each of the passed-in
|
| 114 |
+
ordering keys, if they exist. Clean up state for keys that no longer
|
| 115 |
+
have any queued messages.
|
| 116 |
+
|
| 117 |
+
See comment at streaming_pull_manager.activate_ordering_keys() for more
|
| 118 |
+
detail about the impact of this method on load.
|
| 119 |
+
|
| 120 |
+
Args:
|
| 121 |
+
ordering_keys:
|
| 122 |
+
The ordering keys to activate. May be empty, or contain duplicates.
|
| 123 |
+
schedule_message_callback:
|
| 124 |
+
The callback to call to schedule a message to be sent to the user.
|
| 125 |
+
"""
|
| 126 |
+
for key in ordering_keys:
|
| 127 |
+
pending_ordered_messages = self._pending_ordered_messages.get(key)
|
| 128 |
+
if pending_ordered_messages is None:
|
| 129 |
+
_LOGGER.warning(
|
| 130 |
+
"No message queue exists for message ordering key: %s.", key
|
| 131 |
+
)
|
| 132 |
+
continue
|
| 133 |
+
next_msg = self._get_next_for_ordering_key(key)
|
| 134 |
+
if next_msg:
|
| 135 |
+
# Schedule the next message because the previous was dropped.
|
| 136 |
+
# Note that this may overload the user's `max_bytes` limit, but
|
| 137 |
+
# not their `max_messages` limit.
|
| 138 |
+
schedule_message_callback(next_msg)
|
| 139 |
+
else:
|
| 140 |
+
# No more messages for this ordering key, so do clean-up.
|
| 141 |
+
self._clean_up_ordering_key(key)
|
| 142 |
+
|
| 143 |
+
def _get_next_for_ordering_key(
|
| 144 |
+
self, ordering_key: str
|
| 145 |
+
) -> Optional["subscriber.message.Message"]:
|
| 146 |
+
"""Get next message for ordering key.
|
| 147 |
+
|
| 148 |
+
The client should call clean_up_ordering_key() if this method returns
|
| 149 |
+
None.
|
| 150 |
+
|
| 151 |
+
Args:
|
| 152 |
+
ordering_key: Ordering key for which to get the next message.
|
| 153 |
+
|
| 154 |
+
Returns:
|
| 155 |
+
The next message for this ordering key or None if there aren't any.
|
| 156 |
+
"""
|
| 157 |
+
queue_for_key = self._pending_ordered_messages.get(ordering_key)
|
| 158 |
+
if queue_for_key:
|
| 159 |
+
self._size = self._size - 1
|
| 160 |
+
return queue_for_key.popleft()
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
def _clean_up_ordering_key(self, ordering_key: str) -> None:
|
| 164 |
+
"""Clean up state for an ordering key with no pending messages.
|
| 165 |
+
|
| 166 |
+
Args
|
| 167 |
+
ordering_key: The ordering key to clean up.
|
| 168 |
+
"""
|
| 169 |
+
message_queue = self._pending_ordered_messages.get(ordering_key)
|
| 170 |
+
if message_queue is None:
|
| 171 |
+
_LOGGER.warning(
|
| 172 |
+
"Tried to clean up ordering key that does not exist: %s", ordering_key
|
| 173 |
+
)
|
| 174 |
+
return
|
| 175 |
+
if len(message_queue) > 0:
|
| 176 |
+
_LOGGER.warning(
|
| 177 |
+
"Tried to clean up ordering key: %s with %d messages remaining.",
|
| 178 |
+
ordering_key,
|
| 179 |
+
len(message_queue),
|
| 180 |
+
)
|
| 181 |
+
return
|
| 182 |
+
del self._pending_ordered_messages[ordering_key]
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/requests.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import typing
|
| 16 |
+
from typing import NamedTuple, Optional
|
| 17 |
+
|
| 18 |
+
from google.cloud.pubsub_v1.open_telemetry.subscribe_opentelemetry import (
|
| 19 |
+
SubscribeOpenTelemetry,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 23 |
+
from google.cloud.pubsub_v1.subscriber import futures
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Namedtuples for management requests. Used by the Message class to communicate
|
| 27 |
+
# items of work back to the policy.
|
| 28 |
+
class AckRequest(NamedTuple):
|
| 29 |
+
ack_id: str
|
| 30 |
+
byte_size: int
|
| 31 |
+
time_to_ack: float
|
| 32 |
+
ordering_key: Optional[str]
|
| 33 |
+
future: Optional["futures.Future"]
|
| 34 |
+
opentelemetry_data: Optional[SubscribeOpenTelemetry] = None
|
| 35 |
+
message_id: Optional[str] = None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class DropRequest(NamedTuple):
|
| 39 |
+
ack_id: str
|
| 40 |
+
byte_size: int
|
| 41 |
+
ordering_key: Optional[str]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class LeaseRequest(NamedTuple):
|
| 45 |
+
ack_id: str
|
| 46 |
+
byte_size: int
|
| 47 |
+
ordering_key: Optional[str]
|
| 48 |
+
opentelemetry_data: Optional[SubscribeOpenTelemetry] = None
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class ModAckRequest(NamedTuple):
|
| 52 |
+
ack_id: str
|
| 53 |
+
seconds: float
|
| 54 |
+
future: Optional["futures.Future"]
|
| 55 |
+
opentelemetry_data: Optional[SubscribeOpenTelemetry] = None
|
| 56 |
+
message_id: Optional[str] = None
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class NackRequest(NamedTuple):
|
| 60 |
+
ack_id: str
|
| 61 |
+
byte_size: int
|
| 62 |
+
ordering_key: Optional[str]
|
| 63 |
+
future: Optional["futures.Future"]
|
| 64 |
+
opentelemetry_data: Optional[SubscribeOpenTelemetry] = None
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py
ADDED
|
@@ -0,0 +1,1423 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import division
|
| 16 |
+
|
| 17 |
+
import collections
|
| 18 |
+
import functools
|
| 19 |
+
import inspect
|
| 20 |
+
import itertools
|
| 21 |
+
import logging
|
| 22 |
+
import threading
|
| 23 |
+
import typing
|
| 24 |
+
import uuid
|
| 25 |
+
from typing import (
|
| 26 |
+
Any,
|
| 27 |
+
Callable,
|
| 28 |
+
Dict,
|
| 29 |
+
Iterable,
|
| 30 |
+
List,
|
| 31 |
+
Optional,
|
| 32 |
+
Set,
|
| 33 |
+
Tuple,
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
import grpc # type: ignore
|
| 37 |
+
from google.api_core import bidi, exceptions
|
| 38 |
+
from google.rpc import (
|
| 39 |
+
code_pb2, # type: ignore
|
| 40 |
+
status_pb2,
|
| 41 |
+
)
|
| 42 |
+
from google.rpc.error_details_pb2 import ErrorInfo # type: ignore
|
| 43 |
+
from grpc_status import rpc_status # type: ignore
|
| 44 |
+
from opentelemetry import trace
|
| 45 |
+
|
| 46 |
+
import google.cloud.pubsub_v1.subscriber.message
|
| 47 |
+
from google.cloud.pubsub_v1 import types
|
| 48 |
+
from google.cloud.pubsub_v1.open_telemetry.subscribe_opentelemetry import (
|
| 49 |
+
SubscribeOpenTelemetry,
|
| 50 |
+
start_modack_span,
|
| 51 |
+
)
|
| 52 |
+
from google.cloud.pubsub_v1.subscriber import futures
|
| 53 |
+
from google.cloud.pubsub_v1.subscriber._protocol import (
|
| 54 |
+
dispatcher,
|
| 55 |
+
heartbeater,
|
| 56 |
+
histogram,
|
| 57 |
+
leaser,
|
| 58 |
+
messages_on_hold,
|
| 59 |
+
requests,
|
| 60 |
+
)
|
| 61 |
+
from google.cloud.pubsub_v1.subscriber.exceptions import (
|
| 62 |
+
AcknowledgeError,
|
| 63 |
+
AcknowledgeStatus,
|
| 64 |
+
)
|
| 65 |
+
from google.cloud.pubsub_v1.subscriber.scheduler import ThreadScheduler
|
| 66 |
+
from google.pubsub_v1 import types as gapic_types
|
| 67 |
+
|
| 68 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 69 |
+
from google.cloud.pubsub_v1 import subscriber
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
_LOGGER = logging.getLogger(__name__)
|
| 73 |
+
_SLOW_ACK_LOGGER = logging.getLogger("slow-ack")
|
| 74 |
+
_STREAMS_LOGGER = logging.getLogger("subscriber-streams")
|
| 75 |
+
_FLOW_CONTROL_LOGGER = logging.getLogger("subscriber-flow-control")
|
| 76 |
+
_CALLBACK_DELIVERY_LOGGER = logging.getLogger("callback-delivery")
|
| 77 |
+
_CALLBACK_EXCEPTION_LOGGER = logging.getLogger("callback-exceptions")
|
| 78 |
+
_EXPIRY_LOGGER = logging.getLogger("expiry")
|
| 79 |
+
_REGULAR_SHUTDOWN_THREAD_NAME = "Thread-RegularStreamShutdown"
|
| 80 |
+
_RPC_ERROR_THREAD_NAME = "Thread-OnRpcTerminated"
|
| 81 |
+
_RETRYABLE_STREAM_ERRORS = (
|
| 82 |
+
exceptions.Aborted,
|
| 83 |
+
exceptions.DeadlineExceeded,
|
| 84 |
+
exceptions.GatewayTimeout,
|
| 85 |
+
exceptions.InternalServerError,
|
| 86 |
+
exceptions.ResourceExhausted,
|
| 87 |
+
exceptions.ServiceUnavailable,
|
| 88 |
+
exceptions.Unknown,
|
| 89 |
+
)
|
| 90 |
+
_TERMINATING_STREAM_ERRORS = (
|
| 91 |
+
exceptions.Cancelled,
|
| 92 |
+
exceptions.InvalidArgument,
|
| 93 |
+
exceptions.NotFound,
|
| 94 |
+
exceptions.PermissionDenied,
|
| 95 |
+
exceptions.Unauthenticated,
|
| 96 |
+
exceptions.Unauthorized,
|
| 97 |
+
)
|
| 98 |
+
_MAX_LOAD = 1.0
|
| 99 |
+
"""The load threshold above which to pause the incoming message stream."""
|
| 100 |
+
|
| 101 |
+
_RESUME_THRESHOLD = 0.8
|
| 102 |
+
"""The load threshold below which to resume the incoming message stream."""
|
| 103 |
+
|
| 104 |
+
_MIN_ACK_DEADLINE_SECS_WHEN_EXACTLY_ONCE_ENABLED = 60
|
| 105 |
+
"""The minimum ack_deadline, in seconds, for when exactly_once is enabled for
|
| 106 |
+
a subscription. We do this to reduce premature ack expiration.
|
| 107 |
+
"""
|
| 108 |
+
|
| 109 |
+
_DEFAULT_STREAM_ACK_DEADLINE: float = 60
|
| 110 |
+
"""The default stream ack deadline in seconds."""
|
| 111 |
+
|
| 112 |
+
_MAX_STREAM_ACK_DEADLINE: float = 600
|
| 113 |
+
"""The maximum stream ack deadline in seconds."""
|
| 114 |
+
|
| 115 |
+
_MIN_STREAM_ACK_DEADLINE: float = 10
|
| 116 |
+
"""The minimum stream ack deadline in seconds."""
|
| 117 |
+
|
| 118 |
+
_EXACTLY_ONCE_DELIVERY_TEMPORARY_RETRY_ERRORS = {
|
| 119 |
+
code_pb2.DEADLINE_EXCEEDED,
|
| 120 |
+
code_pb2.RESOURCE_EXHAUSTED,
|
| 121 |
+
code_pb2.ABORTED,
|
| 122 |
+
code_pb2.INTERNAL,
|
| 123 |
+
code_pb2.UNAVAILABLE,
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
# `on_fatal_exception` was added in `google-api-core v2.25.1``, which allows us to inform
|
| 127 |
+
# callers on unrecoverable errors. We can only pass this arg if it's available in the
|
| 128 |
+
# `BackgroundConsumer` spec.
|
| 129 |
+
_SHOULD_USE_ON_FATAL_ERROR_CALLBACK = "on_fatal_exception" in inspect.getfullargspec(
|
| 130 |
+
bidi.BackgroundConsumer
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _wrap_as_exception(maybe_exception: Any) -> BaseException:
|
| 135 |
+
"""Wrap an object as a Python exception, if needed.
|
| 136 |
+
|
| 137 |
+
Args:
|
| 138 |
+
maybe_exception: The object to wrap, usually a gRPC exception class.
|
| 139 |
+
|
| 140 |
+
Returns:
|
| 141 |
+
The argument itself if an instance of ``BaseException``, otherwise
|
| 142 |
+
the argument represented as an instance of ``Exception`` (sub)class.
|
| 143 |
+
"""
|
| 144 |
+
if isinstance(maybe_exception, grpc.RpcError):
|
| 145 |
+
return exceptions.from_grpc_error(maybe_exception)
|
| 146 |
+
elif isinstance(maybe_exception, BaseException):
|
| 147 |
+
return maybe_exception
|
| 148 |
+
|
| 149 |
+
return Exception(maybe_exception)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def _wrap_callback_errors(
|
| 153 |
+
callback: Callable[["google.cloud.pubsub_v1.subscriber.message.Message"], Any],
|
| 154 |
+
on_callback_error: Callable[[BaseException], Any],
|
| 155 |
+
message: "google.cloud.pubsub_v1.subscriber.message.Message",
|
| 156 |
+
):
|
| 157 |
+
"""Wraps a user callback so that if an exception occurs the message is
|
| 158 |
+
nacked.
|
| 159 |
+
|
| 160 |
+
Args:
|
| 161 |
+
callback: The user callback.
|
| 162 |
+
message: The Pub/Sub message.
|
| 163 |
+
"""
|
| 164 |
+
_CALLBACK_DELIVERY_LOGGER.debug(
|
| 165 |
+
"Message (id=%s, ack_id=%s, ordering_key=%s, exactly_once=%s) received by subscriber callback",
|
| 166 |
+
message.message_id,
|
| 167 |
+
message.ack_id,
|
| 168 |
+
message.ordering_key,
|
| 169 |
+
message.exactly_once_enabled,
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
try:
|
| 173 |
+
if message.opentelemetry_data:
|
| 174 |
+
message.opentelemetry_data.end_subscribe_concurrency_control_span()
|
| 175 |
+
with message.opentelemetry_data:
|
| 176 |
+
callback(message)
|
| 177 |
+
else:
|
| 178 |
+
callback(message)
|
| 179 |
+
except BaseException as exc:
|
| 180 |
+
# Note: the likelihood of this failing is extremely low. This just adds
|
| 181 |
+
# a message to a queue, so if this doesn't work the world is in an
|
| 182 |
+
# unrecoverable state and this thread should just bail.
|
| 183 |
+
|
| 184 |
+
_CALLBACK_EXCEPTION_LOGGER.exception(
|
| 185 |
+
"Message (id=%s, ack_id=%s, ordering_key=%s, exactly_once=%s)'s callback threw exception, nacking message.",
|
| 186 |
+
message.message_id,
|
| 187 |
+
message.ack_id,
|
| 188 |
+
message.ordering_key,
|
| 189 |
+
message.exactly_once_enabled,
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
message.nack()
|
| 193 |
+
on_callback_error(exc)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _get_status(
|
| 197 |
+
exc: exceptions.GoogleAPICallError,
|
| 198 |
+
) -> Optional["status_pb2.Status"]:
|
| 199 |
+
if not exc.response:
|
| 200 |
+
_LOGGER.debug("No response obj in errored RPC call.")
|
| 201 |
+
return None
|
| 202 |
+
try:
|
| 203 |
+
return rpc_status.from_call(exc.response)
|
| 204 |
+
# Possible "If the gRPC call’s code or details are inconsistent
|
| 205 |
+
# with the status code and message inside of the
|
| 206 |
+
# google.rpc.status.Status"
|
| 207 |
+
except ValueError:
|
| 208 |
+
_LOGGER.debug("ValueError when parsing ErrorInfo.", exc_info=True)
|
| 209 |
+
return None
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def _get_ack_errors(
|
| 213 |
+
exc: exceptions.GoogleAPICallError,
|
| 214 |
+
) -> Optional[Dict[str, str]]:
|
| 215 |
+
status = _get_status(exc)
|
| 216 |
+
if not status:
|
| 217 |
+
_LOGGER.debug("Unable to get status of errored RPC.")
|
| 218 |
+
return None
|
| 219 |
+
for detail in status.details:
|
| 220 |
+
info = ErrorInfo()
|
| 221 |
+
if not (detail.Is(ErrorInfo.DESCRIPTOR) and detail.Unpack(info)):
|
| 222 |
+
_LOGGER.debug("Unable to unpack ErrorInfo.")
|
| 223 |
+
return None
|
| 224 |
+
return info.metadata
|
| 225 |
+
return None
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def _process_requests(
|
| 229 |
+
error_status: Optional["status_pb2.Status"],
|
| 230 |
+
ack_reqs_dict: Dict[str, requests.AckRequest],
|
| 231 |
+
errors_dict: Optional[Dict[str, str]],
|
| 232 |
+
ack_histogram: Optional[histogram.Histogram] = None,
|
| 233 |
+
# TODO - Change this param to a Union of Literals when we drop p3.7 support
|
| 234 |
+
req_type: str = "ack",
|
| 235 |
+
):
|
| 236 |
+
"""Process requests when exactly-once delivery is enabled by referring to
|
| 237 |
+
error_status and errors_dict.
|
| 238 |
+
|
| 239 |
+
The errors returned by the server in as `error_status` or in `errors_dict`
|
| 240 |
+
are used to complete the request futures in `ack_reqs_dict` (with a success
|
| 241 |
+
or exception) or to return requests for further retries.
|
| 242 |
+
"""
|
| 243 |
+
requests_completed = []
|
| 244 |
+
requests_to_retry = []
|
| 245 |
+
for ack_id, ack_request in ack_reqs_dict.items():
|
| 246 |
+
# Debug logging: slow acks
|
| 247 |
+
if (
|
| 248 |
+
req_type == "ack"
|
| 249 |
+
and ack_histogram
|
| 250 |
+
and ack_request.time_to_ack > ack_histogram.percentile(percent=99)
|
| 251 |
+
):
|
| 252 |
+
_SLOW_ACK_LOGGER.debug(
|
| 253 |
+
"Message (id=%s, ack_id=%s) ack duration of %s s is higher than the p99 ack duration",
|
| 254 |
+
ack_request.message_id,
|
| 255 |
+
ack_request.ack_id,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
# Handle special errors returned for ack/modack RPCs via the ErrorInfo
|
| 259 |
+
# sidecar metadata when exactly-once delivery is enabled.
|
| 260 |
+
if errors_dict and ack_id in errors_dict:
|
| 261 |
+
exactly_once_error = errors_dict[ack_id]
|
| 262 |
+
if exactly_once_error.startswith("TRANSIENT_"):
|
| 263 |
+
requests_to_retry.append(ack_request)
|
| 264 |
+
else:
|
| 265 |
+
if exactly_once_error == "PERMANENT_FAILURE_INVALID_ACK_ID":
|
| 266 |
+
exc = AcknowledgeError(AcknowledgeStatus.INVALID_ACK_ID, info=None)
|
| 267 |
+
else:
|
| 268 |
+
exc = AcknowledgeError(AcknowledgeStatus.OTHER, exactly_once_error)
|
| 269 |
+
future = ack_request.future
|
| 270 |
+
if future is not None:
|
| 271 |
+
future.set_exception(exc)
|
| 272 |
+
requests_completed.append(ack_request)
|
| 273 |
+
# Temporary GRPC errors are retried
|
| 274 |
+
elif (
|
| 275 |
+
error_status
|
| 276 |
+
and error_status.code in _EXACTLY_ONCE_DELIVERY_TEMPORARY_RETRY_ERRORS
|
| 277 |
+
):
|
| 278 |
+
requests_to_retry.append(ack_request)
|
| 279 |
+
# Other GRPC errors are NOT retried
|
| 280 |
+
elif error_status:
|
| 281 |
+
if error_status.code == code_pb2.PERMISSION_DENIED:
|
| 282 |
+
exc = AcknowledgeError(AcknowledgeStatus.PERMISSION_DENIED, info=None)
|
| 283 |
+
elif error_status.code == code_pb2.FAILED_PRECONDITION:
|
| 284 |
+
exc = AcknowledgeError(AcknowledgeStatus.FAILED_PRECONDITION, info=None)
|
| 285 |
+
else:
|
| 286 |
+
exc = AcknowledgeError(AcknowledgeStatus.OTHER, str(error_status))
|
| 287 |
+
future = ack_request.future
|
| 288 |
+
if future is not None:
|
| 289 |
+
future.set_exception(exc)
|
| 290 |
+
requests_completed.append(ack_request)
|
| 291 |
+
# Since no error occurred, requests with futures are completed successfully.
|
| 292 |
+
elif ack_request.future:
|
| 293 |
+
future = ack_request.future
|
| 294 |
+
# success
|
| 295 |
+
assert future is not None
|
| 296 |
+
future.set_result(AcknowledgeStatus.SUCCESS)
|
| 297 |
+
requests_completed.append(ack_request)
|
| 298 |
+
# All other requests are considered completed.
|
| 299 |
+
else:
|
| 300 |
+
requests_completed.append(ack_request)
|
| 301 |
+
|
| 302 |
+
return requests_completed, requests_to_retry
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
class StreamingPullManager(object):
|
| 306 |
+
"""The streaming pull manager coordinates pulling messages from Pub/Sub,
|
| 307 |
+
leasing them, and scheduling them to be processed.
|
| 308 |
+
|
| 309 |
+
Args:
|
| 310 |
+
client:
|
| 311 |
+
The subscriber client used to create this instance.
|
| 312 |
+
subscription:
|
| 313 |
+
The name of the subscription. The canonical format for this is
|
| 314 |
+
``projects/{project}/subscriptions/{subscription}``.
|
| 315 |
+
flow_control:
|
| 316 |
+
The flow control settings.
|
| 317 |
+
scheduler:
|
| 318 |
+
The scheduler to use to process messages. If not provided, a thread
|
| 319 |
+
pool-based scheduler will be used.
|
| 320 |
+
use_legacy_flow_control:
|
| 321 |
+
If set to ``True``, flow control at the Cloud Pub/Sub server is disabled,
|
| 322 |
+
though client-side flow control is still enabled. If set to ``False``
|
| 323 |
+
(default), both server-side and client-side flow control are enabled.
|
| 324 |
+
await_callbacks_on_shutdown:
|
| 325 |
+
If ``True``, the shutdown thread will wait until all scheduler threads
|
| 326 |
+
terminate and only then proceed with shutting down the remaining running
|
| 327 |
+
helper threads.
|
| 328 |
+
|
| 329 |
+
If ``False`` (default), the shutdown thread will shut the scheduler down,
|
| 330 |
+
but it will not wait for the currently executing scheduler threads to
|
| 331 |
+
terminate.
|
| 332 |
+
|
| 333 |
+
This setting affects when the on close callbacks get invoked, and
|
| 334 |
+
consequently, when the StreamingPullFuture associated with the stream gets
|
| 335 |
+
resolved.
|
| 336 |
+
"""
|
| 337 |
+
|
| 338 |
+
def __init__(
|
| 339 |
+
self,
|
| 340 |
+
client: "subscriber.Client",
|
| 341 |
+
subscription: str,
|
| 342 |
+
flow_control: types.FlowControl = types.FlowControl(),
|
| 343 |
+
scheduler: Optional[ThreadScheduler] = None,
|
| 344 |
+
use_legacy_flow_control: bool = False,
|
| 345 |
+
await_callbacks_on_shutdown: bool = False,
|
| 346 |
+
):
|
| 347 |
+
self._client = client
|
| 348 |
+
self._subscription = subscription
|
| 349 |
+
self._exactly_once_enabled = False
|
| 350 |
+
self._flow_control = flow_control
|
| 351 |
+
self._use_legacy_flow_control = use_legacy_flow_control
|
| 352 |
+
self._await_callbacks_on_shutdown = await_callbacks_on_shutdown
|
| 353 |
+
self._ack_histogram = histogram.Histogram()
|
| 354 |
+
self._last_histogram_size = 0
|
| 355 |
+
self._stream_metadata = [
|
| 356 |
+
["x-goog-request-params", "subscription=" + subscription]
|
| 357 |
+
]
|
| 358 |
+
|
| 359 |
+
# If max_duration_per_lease_extension is the default
|
| 360 |
+
# we set the stream_ack_deadline to the default of 60
|
| 361 |
+
if self._flow_control.max_duration_per_lease_extension == 0:
|
| 362 |
+
self._stream_ack_deadline = _DEFAULT_STREAM_ACK_DEADLINE
|
| 363 |
+
# We will not be able to extend more than the default minimum
|
| 364 |
+
elif (
|
| 365 |
+
self._flow_control.max_duration_per_lease_extension
|
| 366 |
+
< _MIN_STREAM_ACK_DEADLINE
|
| 367 |
+
):
|
| 368 |
+
self._stream_ack_deadline = _MIN_STREAM_ACK_DEADLINE
|
| 369 |
+
# Will not be able to extend past the max
|
| 370 |
+
elif (
|
| 371 |
+
self._flow_control.max_duration_per_lease_extension
|
| 372 |
+
> _MAX_STREAM_ACK_DEADLINE
|
| 373 |
+
):
|
| 374 |
+
self._stream_ack_deadline = _MAX_STREAM_ACK_DEADLINE
|
| 375 |
+
else:
|
| 376 |
+
self._stream_ack_deadline = (
|
| 377 |
+
self._flow_control.max_duration_per_lease_extension
|
| 378 |
+
)
|
| 379 |
+
|
| 380 |
+
self._ack_deadline = max(
|
| 381 |
+
min(
|
| 382 |
+
self._flow_control.min_duration_per_lease_extension,
|
| 383 |
+
histogram.MAX_ACK_DEADLINE,
|
| 384 |
+
),
|
| 385 |
+
histogram.MIN_ACK_DEADLINE,
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
self._rpc: Optional[bidi.ResumableBidiRpc] = None
|
| 389 |
+
self._callback: Optional[functools.partial] = None
|
| 390 |
+
self._closing = threading.Lock()
|
| 391 |
+
self._closed = False
|
| 392 |
+
self._close_callbacks: List[Callable[["StreamingPullManager", Any], Any]] = []
|
| 393 |
+
# Guarded by self._exactly_once_enabled_lock
|
| 394 |
+
self._send_new_ack_deadline = False
|
| 395 |
+
|
| 396 |
+
# A shutdown thread is created on intentional shutdown.
|
| 397 |
+
self._regular_shutdown_thread: Optional[threading.Thread] = None
|
| 398 |
+
|
| 399 |
+
# Generate a random client id tied to this object. All streaming pull
|
| 400 |
+
# connections (initial and re-connects) will then use the same client
|
| 401 |
+
# id. Doing so lets the server establish affinity even across stream
|
| 402 |
+
# disconncetions.
|
| 403 |
+
self._client_id = str(uuid.uuid4())
|
| 404 |
+
|
| 405 |
+
if scheduler is None:
|
| 406 |
+
self._scheduler: Optional[ThreadScheduler] = ThreadScheduler()
|
| 407 |
+
else:
|
| 408 |
+
self._scheduler = scheduler
|
| 409 |
+
|
| 410 |
+
# A collection for the messages that have been received from the server,
|
| 411 |
+
# but not yet sent to the user callback.
|
| 412 |
+
self._messages_on_hold = messages_on_hold.MessagesOnHold()
|
| 413 |
+
|
| 414 |
+
# The total number of bytes consumed by the messages currently on hold
|
| 415 |
+
self._on_hold_bytes = 0
|
| 416 |
+
|
| 417 |
+
# A lock ensuring that pausing / resuming the consumer are both atomic
|
| 418 |
+
# operations that cannot be executed concurrently. Needed for properly
|
| 419 |
+
# syncing these operations with the current leaser load. Additionally,
|
| 420 |
+
# the lock is used to protect modifications of internal data that
|
| 421 |
+
# affects the load computation, i.e. the count and size of the messages
|
| 422 |
+
# currently on hold.
|
| 423 |
+
self._pause_resume_lock = threading.Lock()
|
| 424 |
+
|
| 425 |
+
# A lock guarding the self._exactly_once_enabled variable. We may also
|
| 426 |
+
# acquire the self._ack_deadline_lock while this lock is held, but not
|
| 427 |
+
# the reverse. So, we maintain a simple ordering of these two locks to
|
| 428 |
+
# prevent deadlocks.
|
| 429 |
+
self._exactly_once_enabled_lock = threading.Lock()
|
| 430 |
+
|
| 431 |
+
# A lock protecting the current ACK deadline used in the lease management. This
|
| 432 |
+
# value can be potentially updated both by the leaser thread and by the message
|
| 433 |
+
# consumer thread when invoking the internal _on_response() callback.
|
| 434 |
+
self._ack_deadline_lock = threading.Lock()
|
| 435 |
+
|
| 436 |
+
# The threads created in ``.open()``.
|
| 437 |
+
self._dispatcher: Optional[dispatcher.Dispatcher] = None
|
| 438 |
+
self._leaser: Optional[leaser.Leaser] = None
|
| 439 |
+
self._consumer: Optional[bidi.BackgroundConsumer] = None
|
| 440 |
+
self._heartbeater: Optional[heartbeater.Heartbeater] = None
|
| 441 |
+
|
| 442 |
+
@property
|
| 443 |
+
def is_active(self) -> bool:
|
| 444 |
+
"""``True`` if this manager is actively streaming.
|
| 445 |
+
|
| 446 |
+
Note that ``False`` does not indicate this is complete shut down,
|
| 447 |
+
just that it stopped getting new messages.
|
| 448 |
+
"""
|
| 449 |
+
return self._consumer is not None and self._consumer.is_active
|
| 450 |
+
|
| 451 |
+
@property
|
| 452 |
+
def flow_control(self) -> types.FlowControl:
|
| 453 |
+
"""The active flow control settings."""
|
| 454 |
+
return self._flow_control
|
| 455 |
+
|
| 456 |
+
@property
|
| 457 |
+
def dispatcher(self) -> Optional[dispatcher.Dispatcher]:
|
| 458 |
+
"""The dispatcher helper."""
|
| 459 |
+
return self._dispatcher
|
| 460 |
+
|
| 461 |
+
@property
|
| 462 |
+
def leaser(self) -> Optional["leaser.Leaser"]:
|
| 463 |
+
"""The leaser helper."""
|
| 464 |
+
return self._leaser
|
| 465 |
+
|
| 466 |
+
@property
|
| 467 |
+
def ack_histogram(self) -> histogram.Histogram:
|
| 468 |
+
"""The histogram tracking time-to-acknowledge."""
|
| 469 |
+
return self._ack_histogram
|
| 470 |
+
|
| 471 |
+
@property
|
| 472 |
+
def ack_deadline(self) -> float:
|
| 473 |
+
"""Return the current ACK deadline based on historical data without updating it.
|
| 474 |
+
|
| 475 |
+
Returns:
|
| 476 |
+
The ack deadline.
|
| 477 |
+
"""
|
| 478 |
+
return self._obtain_ack_deadline(maybe_update=False)
|
| 479 |
+
|
| 480 |
+
def _obtain_ack_deadline(self, maybe_update: bool) -> float:
|
| 481 |
+
"""The actual `ack_deadline` implementation.
|
| 482 |
+
|
| 483 |
+
This method is "sticky". It will only perform the computations to check on the
|
| 484 |
+
right ACK deadline if explicitly requested AND if the histogram with past
|
| 485 |
+
time-to-ack data has gained a significant amount of new information.
|
| 486 |
+
|
| 487 |
+
Args:
|
| 488 |
+
maybe_update:
|
| 489 |
+
If ``True``, also update the current ACK deadline before returning it if
|
| 490 |
+
enough new ACK data has been gathered.
|
| 491 |
+
|
| 492 |
+
Returns:
|
| 493 |
+
The current ACK deadline in seconds to use.
|
| 494 |
+
"""
|
| 495 |
+
with self._ack_deadline_lock:
|
| 496 |
+
if not maybe_update:
|
| 497 |
+
return self._ack_deadline
|
| 498 |
+
|
| 499 |
+
target_size = min(
|
| 500 |
+
self._last_histogram_size * 2, self._last_histogram_size + 100
|
| 501 |
+
)
|
| 502 |
+
hist_size = len(self.ack_histogram)
|
| 503 |
+
|
| 504 |
+
if hist_size > target_size:
|
| 505 |
+
self._last_histogram_size = hist_size
|
| 506 |
+
self._ack_deadline = self.ack_histogram.percentile(percent=99)
|
| 507 |
+
|
| 508 |
+
if self.flow_control.max_duration_per_lease_extension > 0:
|
| 509 |
+
# The setting in flow control could be too low, adjust if needed.
|
| 510 |
+
flow_control_setting = max(
|
| 511 |
+
self.flow_control.max_duration_per_lease_extension,
|
| 512 |
+
histogram.MIN_ACK_DEADLINE,
|
| 513 |
+
)
|
| 514 |
+
self._ack_deadline = min(self._ack_deadline, flow_control_setting)
|
| 515 |
+
|
| 516 |
+
# If the user explicitly sets a min ack_deadline, respect it.
|
| 517 |
+
if self.flow_control.min_duration_per_lease_extension > 0:
|
| 518 |
+
# The setting in flow control could be too high, adjust if needed.
|
| 519 |
+
flow_control_setting = min(
|
| 520 |
+
self.flow_control.min_duration_per_lease_extension,
|
| 521 |
+
histogram.MAX_ACK_DEADLINE,
|
| 522 |
+
)
|
| 523 |
+
self._ack_deadline = max(self._ack_deadline, flow_control_setting)
|
| 524 |
+
elif self._exactly_once_enabled:
|
| 525 |
+
# Higher minimum ack_deadline for subscriptions with
|
| 526 |
+
# exactly-once delivery enabled.
|
| 527 |
+
self._ack_deadline = max(
|
| 528 |
+
self._ack_deadline, _MIN_ACK_DEADLINE_SECS_WHEN_EXACTLY_ONCE_ENABLED
|
| 529 |
+
)
|
| 530 |
+
# If we have updated the ack_deadline and it is longer than the stream_ack_deadline
|
| 531 |
+
# set the stream_ack_deadline to the new ack_deadline.
|
| 532 |
+
if self._ack_deadline > self._stream_ack_deadline:
|
| 533 |
+
self._stream_ack_deadline = self._ack_deadline
|
| 534 |
+
return self._ack_deadline
|
| 535 |
+
|
| 536 |
+
@property
|
| 537 |
+
def load(self) -> float:
|
| 538 |
+
"""Return the current load.
|
| 539 |
+
|
| 540 |
+
The load is represented as a float, where 1.0 represents having
|
| 541 |
+
hit one of the flow control limits, and values between 0.0 and 1.0
|
| 542 |
+
represent how close we are to them. (0.5 means we have exactly half
|
| 543 |
+
of what the flow control setting allows, for example.)
|
| 544 |
+
|
| 545 |
+
There are (currently) two flow control settings; this property
|
| 546 |
+
computes how close the manager is to each of them, and returns
|
| 547 |
+
whichever value is higher. (It does not matter that we have lots of
|
| 548 |
+
running room on setting A if setting B is over.)
|
| 549 |
+
|
| 550 |
+
Returns:
|
| 551 |
+
The load value.
|
| 552 |
+
"""
|
| 553 |
+
if self._leaser is None:
|
| 554 |
+
return 0.0
|
| 555 |
+
|
| 556 |
+
# Messages that are temporarily put on hold are not being delivered to
|
| 557 |
+
# user's callbacks, thus they should not contribute to the flow control
|
| 558 |
+
# load calculation.
|
| 559 |
+
# However, since these messages must still be lease-managed to avoid
|
| 560 |
+
# unnecessary ACK deadline expirations, their count and total size must
|
| 561 |
+
# be subtracted from the leaser's values.
|
| 562 |
+
return max(
|
| 563 |
+
[
|
| 564 |
+
(self._leaser.message_count - self._messages_on_hold.size)
|
| 565 |
+
/ self._flow_control.max_messages,
|
| 566 |
+
(self._leaser.bytes - self._on_hold_bytes)
|
| 567 |
+
/ self._flow_control.max_bytes,
|
| 568 |
+
]
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
def add_close_callback(
|
| 572 |
+
self, callback: Callable[["StreamingPullManager", Any], Any]
|
| 573 |
+
) -> None:
|
| 574 |
+
"""Schedules a callable when the manager closes.
|
| 575 |
+
|
| 576 |
+
Args:
|
| 577 |
+
The method to call.
|
| 578 |
+
"""
|
| 579 |
+
self._close_callbacks.append(callback)
|
| 580 |
+
|
| 581 |
+
def activate_ordering_keys(self, ordering_keys: Iterable[str]) -> None:
|
| 582 |
+
"""Send the next message in the queue for each of the passed-in
|
| 583 |
+
ordering keys, if they exist. Clean up state for keys that no longer
|
| 584 |
+
have any queued messages.
|
| 585 |
+
|
| 586 |
+
Since the load went down by one message, it's probably safe to send the
|
| 587 |
+
user another message for the same key. Since the released message may be
|
| 588 |
+
bigger than the previous one, this may increase the load above the maximum.
|
| 589 |
+
This decision is by design because it simplifies MessagesOnHold.
|
| 590 |
+
|
| 591 |
+
Args:
|
| 592 |
+
ordering_keys:
|
| 593 |
+
A sequence of ordering keys to activate. May be empty.
|
| 594 |
+
"""
|
| 595 |
+
with self._pause_resume_lock:
|
| 596 |
+
if self._scheduler is None:
|
| 597 |
+
return # We are shutting down, don't try to dispatch any more messages.
|
| 598 |
+
|
| 599 |
+
self._messages_on_hold.activate_ordering_keys(
|
| 600 |
+
ordering_keys, self._schedule_message_on_hold
|
| 601 |
+
)
|
| 602 |
+
|
| 603 |
+
def maybe_pause_consumer(self) -> None:
|
| 604 |
+
"""Check the current load and pause the consumer if needed."""
|
| 605 |
+
with self._pause_resume_lock:
|
| 606 |
+
if self.load >= _MAX_LOAD:
|
| 607 |
+
if self._consumer is not None and not self._consumer.is_paused:
|
| 608 |
+
_FLOW_CONTROL_LOGGER.debug(
|
| 609 |
+
"Message backlog over load at %.2f (threshold %.2f), initiating client-side flow control",
|
| 610 |
+
self.load,
|
| 611 |
+
_RESUME_THRESHOLD,
|
| 612 |
+
)
|
| 613 |
+
self._consumer.pause()
|
| 614 |
+
|
| 615 |
+
def maybe_resume_consumer(self) -> None:
|
| 616 |
+
"""Check the load and held messages and resume the consumer if needed.
|
| 617 |
+
|
| 618 |
+
If there are messages held internally, release those messages before
|
| 619 |
+
resuming the consumer. That will avoid leaser overload.
|
| 620 |
+
"""
|
| 621 |
+
with self._pause_resume_lock:
|
| 622 |
+
# If we have been paused by flow control, check and see if we are
|
| 623 |
+
# back within our limits.
|
| 624 |
+
#
|
| 625 |
+
# In order to not thrash too much, require us to have passed below
|
| 626 |
+
# the resume threshold (80% by default) of each flow control setting
|
| 627 |
+
# before restarting.
|
| 628 |
+
if self._consumer is None or not self._consumer.is_paused:
|
| 629 |
+
return
|
| 630 |
+
|
| 631 |
+
_LOGGER.debug("Current load: %.2f", self.load)
|
| 632 |
+
|
| 633 |
+
# Before maybe resuming the background consumer, release any messages
|
| 634 |
+
# currently on hold, if the current load allows for it.
|
| 635 |
+
self._maybe_release_messages()
|
| 636 |
+
|
| 637 |
+
if self.load < _RESUME_THRESHOLD:
|
| 638 |
+
_FLOW_CONTROL_LOGGER.debug(
|
| 639 |
+
"Current load is %.2f (threshold %.2f), suspending client-side flow control.",
|
| 640 |
+
self.load,
|
| 641 |
+
_RESUME_THRESHOLD,
|
| 642 |
+
)
|
| 643 |
+
self._consumer.resume()
|
| 644 |
+
else:
|
| 645 |
+
_FLOW_CONTROL_LOGGER.debug(
|
| 646 |
+
"Current load is %.2f (threshold %.2f), retaining client-side flow control.",
|
| 647 |
+
self.load,
|
| 648 |
+
_RESUME_THRESHOLD,
|
| 649 |
+
)
|
| 650 |
+
|
| 651 |
+
def _maybe_release_messages(self) -> None:
|
| 652 |
+
"""Release (some of) the held messages if the current load allows for it.
|
| 653 |
+
|
| 654 |
+
The method tries to release as many messages as the current leaser load
|
| 655 |
+
would allow. Each released message is added to the lease management,
|
| 656 |
+
and the user callback is scheduled for it.
|
| 657 |
+
|
| 658 |
+
If there are currently no messages on hold, or if the leaser is
|
| 659 |
+
already overloaded, this method is effectively a no-op.
|
| 660 |
+
|
| 661 |
+
The method assumes the caller has acquired the ``_pause_resume_lock``.
|
| 662 |
+
"""
|
| 663 |
+
released_ack_ids = []
|
| 664 |
+
while self.load < _MAX_LOAD:
|
| 665 |
+
msg = self._messages_on_hold.get()
|
| 666 |
+
if not msg:
|
| 667 |
+
break
|
| 668 |
+
if msg.opentelemetry_data:
|
| 669 |
+
msg.opentelemetry_data.end_subscribe_scheduler_span()
|
| 670 |
+
self._schedule_message_on_hold(msg)
|
| 671 |
+
released_ack_ids.append(msg.ack_id)
|
| 672 |
+
|
| 673 |
+
assert self._leaser is not None
|
| 674 |
+
self._leaser.start_lease_expiry_timer(released_ack_ids)
|
| 675 |
+
|
| 676 |
+
def _schedule_message_on_hold(
|
| 677 |
+
self, msg: "google.cloud.pubsub_v1.subscriber.message.Message"
|
| 678 |
+
):
|
| 679 |
+
"""Schedule a message on hold to be sent to the user and change on-hold-bytes.
|
| 680 |
+
|
| 681 |
+
The method assumes the caller has acquired the ``_pause_resume_lock``.
|
| 682 |
+
|
| 683 |
+
Args:
|
| 684 |
+
msg: The message to schedule to be sent to the user.
|
| 685 |
+
"""
|
| 686 |
+
assert msg, "Message must not be None."
|
| 687 |
+
|
| 688 |
+
# On-hold bytes goes down, increasing load.
|
| 689 |
+
self._on_hold_bytes -= msg.size
|
| 690 |
+
|
| 691 |
+
if self._on_hold_bytes < 0:
|
| 692 |
+
_LOGGER.warning(
|
| 693 |
+
"On hold bytes was unexpectedly negative: %s", self._on_hold_bytes
|
| 694 |
+
)
|
| 695 |
+
self._on_hold_bytes = 0
|
| 696 |
+
|
| 697 |
+
_LOGGER.debug(
|
| 698 |
+
"Released held message, scheduling callback for it, "
|
| 699 |
+
"still on hold %s (bytes %s).",
|
| 700 |
+
self._messages_on_hold.size,
|
| 701 |
+
self._on_hold_bytes,
|
| 702 |
+
)
|
| 703 |
+
assert self._scheduler is not None
|
| 704 |
+
assert self._callback is not None
|
| 705 |
+
if msg.opentelemetry_data:
|
| 706 |
+
msg.opentelemetry_data.start_subscribe_concurrency_control_span()
|
| 707 |
+
self._scheduler.schedule(self._callback, msg)
|
| 708 |
+
|
| 709 |
+
def send_unary_ack(
|
| 710 |
+
self, ack_ids, ack_reqs_dict
|
| 711 |
+
) -> Tuple[List[requests.AckRequest], List[requests.AckRequest]]:
|
| 712 |
+
"""Send a request using a separate unary request instead of over the stream.
|
| 713 |
+
|
| 714 |
+
If a RetryError occurs, the manager shutdown is triggered, and the
|
| 715 |
+
error is re-raised.
|
| 716 |
+
"""
|
| 717 |
+
assert ack_ids
|
| 718 |
+
assert len(ack_ids) == len(ack_reqs_dict)
|
| 719 |
+
|
| 720 |
+
error_status = None
|
| 721 |
+
ack_errors_dict = None
|
| 722 |
+
try:
|
| 723 |
+
self._client.acknowledge(subscription=self._subscription, ack_ids=ack_ids)
|
| 724 |
+
except exceptions.GoogleAPICallError as exc:
|
| 725 |
+
_LOGGER.debug(
|
| 726 |
+
"Exception while sending unary RPC. This is typically "
|
| 727 |
+
"non-fatal as stream requests are best-effort.",
|
| 728 |
+
exc_info=True,
|
| 729 |
+
)
|
| 730 |
+
error_status = _get_status(exc)
|
| 731 |
+
ack_errors_dict = _get_ack_errors(exc)
|
| 732 |
+
except exceptions.RetryError as exc:
|
| 733 |
+
exactly_once_delivery_enabled = self._exactly_once_delivery_enabled()
|
| 734 |
+
# Makes sure to complete futures so they don't block forever.
|
| 735 |
+
for req in ack_reqs_dict.values():
|
| 736 |
+
# Futures may be present even with exactly-once delivery
|
| 737 |
+
# disabled, in transition periods after the setting is changed on
|
| 738 |
+
# the subscription.
|
| 739 |
+
if req.future:
|
| 740 |
+
if exactly_once_delivery_enabled:
|
| 741 |
+
e = AcknowledgeError(
|
| 742 |
+
AcknowledgeStatus.OTHER, "RetryError while sending ack RPC."
|
| 743 |
+
)
|
| 744 |
+
req.future.set_exception(e)
|
| 745 |
+
else:
|
| 746 |
+
req.future.set_result(AcknowledgeStatus.SUCCESS)
|
| 747 |
+
|
| 748 |
+
_LOGGER.debug(
|
| 749 |
+
"RetryError while sending ack RPC. Waiting on a transient "
|
| 750 |
+
"error resolution for too long, will now trigger shutdown.",
|
| 751 |
+
exc_info=False,
|
| 752 |
+
)
|
| 753 |
+
# The underlying channel has been suffering from a retryable error
|
| 754 |
+
# for too long, time to give up and shut the streaming pull down.
|
| 755 |
+
self._on_rpc_done(exc)
|
| 756 |
+
raise
|
| 757 |
+
|
| 758 |
+
if self._exactly_once_delivery_enabled():
|
| 759 |
+
requests_completed, requests_to_retry = _process_requests(
|
| 760 |
+
error_status, ack_reqs_dict, ack_errors_dict, self.ack_histogram, "ack"
|
| 761 |
+
)
|
| 762 |
+
else:
|
| 763 |
+
requests_completed = []
|
| 764 |
+
requests_to_retry = []
|
| 765 |
+
# When exactly-once delivery is NOT enabled, acks/modacks are considered
|
| 766 |
+
# best-effort. So, they always succeed even if the RPC fails.
|
| 767 |
+
for req in ack_reqs_dict.values():
|
| 768 |
+
# Futures may be present even with exactly-once delivery
|
| 769 |
+
# disabled, in transition periods after the setting is changed on
|
| 770 |
+
# the subscription.
|
| 771 |
+
if req.future:
|
| 772 |
+
req.future.set_result(AcknowledgeStatus.SUCCESS)
|
| 773 |
+
requests_completed.append(req)
|
| 774 |
+
|
| 775 |
+
return requests_completed, requests_to_retry
|
| 776 |
+
|
| 777 |
+
def send_unary_modack(
|
| 778 |
+
self,
|
| 779 |
+
modify_deadline_ack_ids,
|
| 780 |
+
modify_deadline_seconds,
|
| 781 |
+
ack_reqs_dict,
|
| 782 |
+
default_deadline=None,
|
| 783 |
+
) -> Tuple[List[requests.ModAckRequest], List[requests.ModAckRequest]]:
|
| 784 |
+
"""Send a request using a separate unary request instead of over the stream.
|
| 785 |
+
|
| 786 |
+
If a RetryError occurs, the manager shutdown is triggered, and the
|
| 787 |
+
error is re-raised.
|
| 788 |
+
"""
|
| 789 |
+
assert modify_deadline_ack_ids
|
| 790 |
+
# Either we have a generator or a single deadline.
|
| 791 |
+
assert modify_deadline_seconds is None or default_deadline is None
|
| 792 |
+
|
| 793 |
+
error_status = None
|
| 794 |
+
modack_errors_dict = None
|
| 795 |
+
try:
|
| 796 |
+
if default_deadline is None:
|
| 797 |
+
# Send ack_ids with the same deadline seconds together.
|
| 798 |
+
deadline_to_ack_ids = collections.defaultdict(list)
|
| 799 |
+
|
| 800 |
+
for n, ack_id in enumerate(modify_deadline_ack_ids):
|
| 801 |
+
deadline = modify_deadline_seconds[n]
|
| 802 |
+
deadline_to_ack_ids[deadline].append(ack_id)
|
| 803 |
+
|
| 804 |
+
for deadline, ack_ids in deadline_to_ack_ids.items():
|
| 805 |
+
self._client.modify_ack_deadline(
|
| 806 |
+
subscription=self._subscription,
|
| 807 |
+
ack_ids=ack_ids,
|
| 808 |
+
ack_deadline_seconds=deadline,
|
| 809 |
+
)
|
| 810 |
+
else:
|
| 811 |
+
# We can send all requests with the default deadline.
|
| 812 |
+
self._client.modify_ack_deadline(
|
| 813 |
+
subscription=self._subscription,
|
| 814 |
+
ack_ids=modify_deadline_ack_ids,
|
| 815 |
+
ack_deadline_seconds=default_deadline,
|
| 816 |
+
)
|
| 817 |
+
except exceptions.GoogleAPICallError as exc:
|
| 818 |
+
_LOGGER.debug(
|
| 819 |
+
"Exception while sending unary RPC. This is typically "
|
| 820 |
+
"non-fatal as stream requests are best-effort.",
|
| 821 |
+
exc_info=True,
|
| 822 |
+
)
|
| 823 |
+
error_status = _get_status(exc)
|
| 824 |
+
modack_errors_dict = _get_ack_errors(exc)
|
| 825 |
+
except exceptions.RetryError as exc:
|
| 826 |
+
exactly_once_delivery_enabled = self._exactly_once_delivery_enabled()
|
| 827 |
+
# Makes sure to complete futures so they don't block forever.
|
| 828 |
+
for req in ack_reqs_dict.values():
|
| 829 |
+
# Futures may be present even with exactly-once delivery
|
| 830 |
+
# disabled, in transition periods after the setting is changed on
|
| 831 |
+
# the subscription.
|
| 832 |
+
if req.future:
|
| 833 |
+
if exactly_once_delivery_enabled:
|
| 834 |
+
e = AcknowledgeError(
|
| 835 |
+
AcknowledgeStatus.OTHER,
|
| 836 |
+
"RetryError while sending modack RPC.",
|
| 837 |
+
)
|
| 838 |
+
req.future.set_exception(e)
|
| 839 |
+
else:
|
| 840 |
+
req.future.set_result(AcknowledgeStatus.SUCCESS)
|
| 841 |
+
|
| 842 |
+
_LOGGER.debug(
|
| 843 |
+
"RetryError while sending modack RPC. Waiting on a transient "
|
| 844 |
+
"error resolution for too long, will now trigger shutdown.",
|
| 845 |
+
exc_info=False,
|
| 846 |
+
)
|
| 847 |
+
# The underlying channel has been suffering from a retryable error
|
| 848 |
+
# for too long, time to give up and shut the streaming pull down.
|
| 849 |
+
self._on_rpc_done(exc)
|
| 850 |
+
raise
|
| 851 |
+
|
| 852 |
+
if self._exactly_once_delivery_enabled():
|
| 853 |
+
requests_completed, requests_to_retry = _process_requests(
|
| 854 |
+
error_status,
|
| 855 |
+
ack_reqs_dict,
|
| 856 |
+
modack_errors_dict,
|
| 857 |
+
self.ack_histogram,
|
| 858 |
+
"modack",
|
| 859 |
+
)
|
| 860 |
+
else:
|
| 861 |
+
requests_completed = []
|
| 862 |
+
requests_to_retry = []
|
| 863 |
+
# When exactly-once delivery is NOT enabled, acks/modacks are considered
|
| 864 |
+
# best-effort. So, they always succeed even if the RPC fails.
|
| 865 |
+
for req in ack_reqs_dict.values():
|
| 866 |
+
# Futures may be present even with exactly-once delivery
|
| 867 |
+
# disabled, in transition periods after the setting is changed on
|
| 868 |
+
# the subscription.
|
| 869 |
+
if req.future:
|
| 870 |
+
req.future.set_result(AcknowledgeStatus.SUCCESS)
|
| 871 |
+
requests_completed.append(req)
|
| 872 |
+
|
| 873 |
+
return requests_completed, requests_to_retry
|
| 874 |
+
|
| 875 |
+
def heartbeat(self) -> bool:
|
| 876 |
+
"""Sends a heartbeat request over the streaming pull RPC.
|
| 877 |
+
|
| 878 |
+
The request is empty by default, but may contain the current ack_deadline
|
| 879 |
+
if the self._exactly_once_enabled flag has changed.
|
| 880 |
+
|
| 881 |
+
Returns:
|
| 882 |
+
If a heartbeat request has actually been sent.
|
| 883 |
+
"""
|
| 884 |
+
if self._rpc is not None and self._rpc.is_active:
|
| 885 |
+
send_new_ack_deadline = False
|
| 886 |
+
with self._exactly_once_enabled_lock:
|
| 887 |
+
send_new_ack_deadline = self._send_new_ack_deadline
|
| 888 |
+
self._send_new_ack_deadline = False
|
| 889 |
+
|
| 890 |
+
if send_new_ack_deadline:
|
| 891 |
+
request = gapic_types.StreamingPullRequest(
|
| 892 |
+
stream_ack_deadline_seconds=self._stream_ack_deadline
|
| 893 |
+
)
|
| 894 |
+
_LOGGER.debug(
|
| 895 |
+
"Sending new ack_deadline of %d seconds.", self._stream_ack_deadline
|
| 896 |
+
)
|
| 897 |
+
else:
|
| 898 |
+
request = gapic_types.StreamingPullRequest()
|
| 899 |
+
|
| 900 |
+
self._rpc.send(request)
|
| 901 |
+
return True
|
| 902 |
+
|
| 903 |
+
return False
|
| 904 |
+
|
| 905 |
+
def open(
|
| 906 |
+
self,
|
| 907 |
+
callback: Callable[["google.cloud.pubsub_v1.subscriber.message.Message"], Any],
|
| 908 |
+
on_callback_error: Callable[[Exception], Any],
|
| 909 |
+
) -> None:
|
| 910 |
+
"""Begin consuming messages.
|
| 911 |
+
|
| 912 |
+
Args:
|
| 913 |
+
callback:
|
| 914 |
+
A callback that will be called for each message received on the
|
| 915 |
+
stream.
|
| 916 |
+
on_callback_error:
|
| 917 |
+
A callable that will be called if an exception is raised in
|
| 918 |
+
the provided `callback`.
|
| 919 |
+
"""
|
| 920 |
+
if self.is_active:
|
| 921 |
+
raise ValueError("This manager is already open.")
|
| 922 |
+
|
| 923 |
+
if self._closed:
|
| 924 |
+
raise ValueError("This manager has been closed and can not be re-used.")
|
| 925 |
+
|
| 926 |
+
self._callback = functools.partial(
|
| 927 |
+
_wrap_callback_errors, callback, on_callback_error
|
| 928 |
+
)
|
| 929 |
+
|
| 930 |
+
# Create the RPC
|
| 931 |
+
stream_ack_deadline_seconds = self._stream_ack_deadline
|
| 932 |
+
|
| 933 |
+
get_initial_request = functools.partial(
|
| 934 |
+
self._get_initial_request, stream_ack_deadline_seconds
|
| 935 |
+
)
|
| 936 |
+
self._rpc = bidi.ResumableBidiRpc(
|
| 937 |
+
start_rpc=self._client.streaming_pull,
|
| 938 |
+
initial_request=get_initial_request,
|
| 939 |
+
should_recover=self._should_recover,
|
| 940 |
+
should_terminate=self._should_terminate,
|
| 941 |
+
metadata=self._stream_metadata,
|
| 942 |
+
throttle_reopen=True,
|
| 943 |
+
)
|
| 944 |
+
self._rpc.add_done_callback(self._on_rpc_done)
|
| 945 |
+
|
| 946 |
+
_LOGGER.debug(
|
| 947 |
+
"Creating a stream, default ACK deadline set to {} seconds.".format(
|
| 948 |
+
self._stream_ack_deadline
|
| 949 |
+
)
|
| 950 |
+
)
|
| 951 |
+
|
| 952 |
+
# Create references to threads
|
| 953 |
+
assert self._scheduler is not None
|
| 954 |
+
scheduler_queue = self._scheduler.queue
|
| 955 |
+
self._dispatcher = dispatcher.Dispatcher(self, scheduler_queue)
|
| 956 |
+
|
| 957 |
+
# `on_fatal_exception` is only available in more recent library versions.
|
| 958 |
+
# For backwards compatibility reasons, we only pass it when `google-api-core` supports it.
|
| 959 |
+
if _SHOULD_USE_ON_FATAL_ERROR_CALLBACK:
|
| 960 |
+
self._consumer = bidi.BackgroundConsumer(
|
| 961 |
+
self._rpc,
|
| 962 |
+
self._on_response,
|
| 963 |
+
on_fatal_exception=self._on_fatal_exception,
|
| 964 |
+
)
|
| 965 |
+
else:
|
| 966 |
+
self._consumer = bidi.BackgroundConsumer(self._rpc, self._on_response)
|
| 967 |
+
|
| 968 |
+
self._leaser = leaser.Leaser(self)
|
| 969 |
+
self._heartbeater = heartbeater.Heartbeater(self)
|
| 970 |
+
|
| 971 |
+
# Start the thread to pass the requests.
|
| 972 |
+
self._dispatcher.start()
|
| 973 |
+
|
| 974 |
+
# Start consuming messages.
|
| 975 |
+
self._consumer.start()
|
| 976 |
+
|
| 977 |
+
# Start the lease maintainer thread.
|
| 978 |
+
self._leaser.start()
|
| 979 |
+
|
| 980 |
+
# Start the stream heartbeater thread.
|
| 981 |
+
self._heartbeater.start()
|
| 982 |
+
|
| 983 |
+
def close(self, reason: Any = None) -> None:
|
| 984 |
+
"""Stop consuming messages and shutdown all helper threads.
|
| 985 |
+
|
| 986 |
+
This method is idempotent. Additional calls will have no effect.
|
| 987 |
+
|
| 988 |
+
The method does not block, it delegates the shutdown operations to a background
|
| 989 |
+
thread.
|
| 990 |
+
|
| 991 |
+
Args:
|
| 992 |
+
reason:
|
| 993 |
+
The reason to close this. If ``None``, this is considered
|
| 994 |
+
an "intentional" shutdown. This is passed to the callbacks
|
| 995 |
+
specified via :meth:`add_close_callback`.
|
| 996 |
+
"""
|
| 997 |
+
self._regular_shutdown_thread = threading.Thread(
|
| 998 |
+
name=_REGULAR_SHUTDOWN_THREAD_NAME,
|
| 999 |
+
daemon=True,
|
| 1000 |
+
target=self._shutdown,
|
| 1001 |
+
kwargs={"reason": reason},
|
| 1002 |
+
)
|
| 1003 |
+
self._regular_shutdown_thread.start()
|
| 1004 |
+
|
| 1005 |
+
def _shutdown(self, reason: Any = None) -> None:
|
| 1006 |
+
"""Run the actual shutdown sequence (stop the stream and all helper threads).
|
| 1007 |
+
|
| 1008 |
+
Args:
|
| 1009 |
+
reason:
|
| 1010 |
+
The reason to close the stream. If ``None``, this is considered
|
| 1011 |
+
an "intentional" shutdown.
|
| 1012 |
+
"""
|
| 1013 |
+
with self._closing:
|
| 1014 |
+
if self._closed:
|
| 1015 |
+
return
|
| 1016 |
+
|
| 1017 |
+
# Stop consuming messages.
|
| 1018 |
+
if self.is_active:
|
| 1019 |
+
_LOGGER.debug("Stopping consumer.")
|
| 1020 |
+
assert self._consumer is not None
|
| 1021 |
+
self._consumer.stop()
|
| 1022 |
+
self._consumer = None
|
| 1023 |
+
|
| 1024 |
+
# Shutdown all helper threads
|
| 1025 |
+
_LOGGER.debug("Stopping scheduler.")
|
| 1026 |
+
assert self._scheduler is not None
|
| 1027 |
+
dropped_messages = self._scheduler.shutdown(
|
| 1028 |
+
await_msg_callbacks=self._await_callbacks_on_shutdown
|
| 1029 |
+
)
|
| 1030 |
+
self._scheduler = None
|
| 1031 |
+
|
| 1032 |
+
# Leaser and dispatcher reference each other through the shared
|
| 1033 |
+
# StreamingPullManager instance, i.e. "self", thus do not set their
|
| 1034 |
+
# references to None until both have been shut down.
|
| 1035 |
+
#
|
| 1036 |
+
# NOTE: Even if the dispatcher operates on an inactive leaser using
|
| 1037 |
+
# the latter's add() and remove() methods, these have no impact on
|
| 1038 |
+
# the stopped leaser (the leaser is never again re-started). Ditto
|
| 1039 |
+
# for the manager's maybe_resume_consumer() / maybe_pause_consumer(),
|
| 1040 |
+
# because the consumer gets shut down first.
|
| 1041 |
+
_LOGGER.debug("Stopping leaser.")
|
| 1042 |
+
assert self._leaser is not None
|
| 1043 |
+
self._leaser.stop()
|
| 1044 |
+
|
| 1045 |
+
total = len(dropped_messages) + len(
|
| 1046 |
+
self._messages_on_hold._messages_on_hold
|
| 1047 |
+
)
|
| 1048 |
+
_LOGGER.debug(f"NACK-ing all not-yet-dispatched messages (total: {total}).")
|
| 1049 |
+
messages_to_nack = itertools.chain(
|
| 1050 |
+
dropped_messages, self._messages_on_hold._messages_on_hold
|
| 1051 |
+
)
|
| 1052 |
+
for msg in messages_to_nack:
|
| 1053 |
+
msg.nack()
|
| 1054 |
+
|
| 1055 |
+
_LOGGER.debug("Stopping dispatcher.")
|
| 1056 |
+
assert self._dispatcher is not None
|
| 1057 |
+
self._dispatcher.stop()
|
| 1058 |
+
self._dispatcher = None
|
| 1059 |
+
# dispatcher terminated, OK to dispose the leaser reference now
|
| 1060 |
+
self._leaser = None
|
| 1061 |
+
|
| 1062 |
+
_LOGGER.debug("Stopping heartbeater.")
|
| 1063 |
+
assert self._heartbeater is not None
|
| 1064 |
+
self._heartbeater.stop()
|
| 1065 |
+
self._heartbeater = None
|
| 1066 |
+
|
| 1067 |
+
self._rpc = None
|
| 1068 |
+
self._closed = True
|
| 1069 |
+
_LOGGER.debug("Finished stopping manager.")
|
| 1070 |
+
|
| 1071 |
+
for callback in self._close_callbacks:
|
| 1072 |
+
callback(self, reason)
|
| 1073 |
+
|
| 1074 |
+
def _get_initial_request(
|
| 1075 |
+
self, stream_ack_deadline_seconds: int
|
| 1076 |
+
) -> gapic_types.StreamingPullRequest:
|
| 1077 |
+
"""Return the initial request for the RPC.
|
| 1078 |
+
|
| 1079 |
+
This defines the initial request that must always be sent to Pub/Sub
|
| 1080 |
+
immediately upon opening the subscription.
|
| 1081 |
+
|
| 1082 |
+
Args:
|
| 1083 |
+
stream_ack_deadline_seconds:
|
| 1084 |
+
The default message acknowledge deadline for the stream.
|
| 1085 |
+
|
| 1086 |
+
Returns:
|
| 1087 |
+
A request suitable for being the first request on the stream (and not
|
| 1088 |
+
suitable for any other purpose).
|
| 1089 |
+
"""
|
| 1090 |
+
# Put the request together.
|
| 1091 |
+
# We need to set streaming ack deadline, but it's not useful since we'll modack to send receipt
|
| 1092 |
+
# anyway. Set to some big-ish value in case we modack late.
|
| 1093 |
+
request = gapic_types.StreamingPullRequest(
|
| 1094 |
+
stream_ack_deadline_seconds=stream_ack_deadline_seconds,
|
| 1095 |
+
modify_deadline_ack_ids=[],
|
| 1096 |
+
modify_deadline_seconds=[],
|
| 1097 |
+
subscription=self._subscription,
|
| 1098 |
+
client_id=self._client_id,
|
| 1099 |
+
max_outstanding_messages=(
|
| 1100 |
+
0 if self._use_legacy_flow_control else self._flow_control.max_messages
|
| 1101 |
+
),
|
| 1102 |
+
max_outstanding_bytes=(
|
| 1103 |
+
0 if self._use_legacy_flow_control else self._flow_control.max_bytes
|
| 1104 |
+
),
|
| 1105 |
+
)
|
| 1106 |
+
|
| 1107 |
+
# Return the initial request.
|
| 1108 |
+
return request
|
| 1109 |
+
|
| 1110 |
+
def _send_lease_modacks(
|
| 1111 |
+
self,
|
| 1112 |
+
ack_ids: Iterable[str],
|
| 1113 |
+
ack_deadline: float,
|
| 1114 |
+
opentelemetry_data: List[SubscribeOpenTelemetry],
|
| 1115 |
+
warn_on_invalid=True,
|
| 1116 |
+
receipt_modack: bool = False,
|
| 1117 |
+
) -> Set[str]:
|
| 1118 |
+
exactly_once_enabled = False
|
| 1119 |
+
|
| 1120 |
+
modack_span: Optional[trace.Span] = None
|
| 1121 |
+
if self._client.open_telemetry_enabled:
|
| 1122 |
+
subscribe_span_links: List[trace.Link] = []
|
| 1123 |
+
subscribe_spans: List[trace.Span] = []
|
| 1124 |
+
subscription_split: List[str] = self._subscription.split("/")
|
| 1125 |
+
assert len(subscription_split) == 4
|
| 1126 |
+
subscription_id: str = subscription_split[3]
|
| 1127 |
+
project_id: str = subscription_split[1]
|
| 1128 |
+
for data in opentelemetry_data:
|
| 1129 |
+
subscribe_span: Optional[trace.Span] = data.subscribe_span
|
| 1130 |
+
if (
|
| 1131 |
+
subscribe_span
|
| 1132 |
+
and subscribe_span.get_span_context().trace_flags.sampled
|
| 1133 |
+
):
|
| 1134 |
+
subscribe_span_links.append(
|
| 1135 |
+
trace.Link(subscribe_span.get_span_context())
|
| 1136 |
+
)
|
| 1137 |
+
subscribe_spans.append(subscribe_span)
|
| 1138 |
+
modack_span = start_modack_span(
|
| 1139 |
+
subscribe_span_links,
|
| 1140 |
+
subscription_id,
|
| 1141 |
+
len(opentelemetry_data),
|
| 1142 |
+
ack_deadline,
|
| 1143 |
+
project_id,
|
| 1144 |
+
"_send_lease_modacks",
|
| 1145 |
+
receipt_modack,
|
| 1146 |
+
)
|
| 1147 |
+
if (
|
| 1148 |
+
modack_span and modack_span.get_span_context().trace_flags.sampled
|
| 1149 |
+
): # pragma: NO COVER
|
| 1150 |
+
modack_span_context: trace.SpanContext = modack_span.get_span_context()
|
| 1151 |
+
for subscribe_span in subscribe_spans:
|
| 1152 |
+
subscribe_span.add_link(
|
| 1153 |
+
context=modack_span_context,
|
| 1154 |
+
attributes={
|
| 1155 |
+
"messaging.operation.name": "modack",
|
| 1156 |
+
},
|
| 1157 |
+
)
|
| 1158 |
+
|
| 1159 |
+
with self._exactly_once_enabled_lock:
|
| 1160 |
+
exactly_once_enabled = self._exactly_once_enabled
|
| 1161 |
+
if exactly_once_enabled:
|
| 1162 |
+
eod_items: List[requests.ModAckRequest] = []
|
| 1163 |
+
if self._client.open_telemetry_enabled:
|
| 1164 |
+
for ack_id, data in zip(
|
| 1165 |
+
ack_ids, opentelemetry_data
|
| 1166 |
+
): # pragma: NO COVER # Identical code covered in the same function below
|
| 1167 |
+
assert data is not None
|
| 1168 |
+
eod_items.append(
|
| 1169 |
+
requests.ModAckRequest(
|
| 1170 |
+
ack_id,
|
| 1171 |
+
ack_deadline,
|
| 1172 |
+
futures.Future(),
|
| 1173 |
+
data,
|
| 1174 |
+
)
|
| 1175 |
+
)
|
| 1176 |
+
else:
|
| 1177 |
+
eod_items = [
|
| 1178 |
+
requests.ModAckRequest(ack_id, ack_deadline, futures.Future())
|
| 1179 |
+
for ack_id in ack_ids
|
| 1180 |
+
]
|
| 1181 |
+
|
| 1182 |
+
assert self._dispatcher is not None
|
| 1183 |
+
self._dispatcher.modify_ack_deadline(eod_items, ack_deadline)
|
| 1184 |
+
if (
|
| 1185 |
+
modack_span
|
| 1186 |
+
): # pragma: NO COVER # Identical code covered in the same function below
|
| 1187 |
+
modack_span.end()
|
| 1188 |
+
expired_ack_ids = set()
|
| 1189 |
+
for req in eod_items:
|
| 1190 |
+
try:
|
| 1191 |
+
assert req.future is not None
|
| 1192 |
+
req.future.result()
|
| 1193 |
+
except AcknowledgeError as ack_error:
|
| 1194 |
+
if (
|
| 1195 |
+
ack_error.error_code != AcknowledgeStatus.INVALID_ACK_ID
|
| 1196 |
+
or warn_on_invalid
|
| 1197 |
+
):
|
| 1198 |
+
_LOGGER.warning(
|
| 1199 |
+
"AcknowledgeError when lease-modacking a message.",
|
| 1200 |
+
exc_info=True,
|
| 1201 |
+
)
|
| 1202 |
+
if ack_error.error_code == AcknowledgeStatus.INVALID_ACK_ID:
|
| 1203 |
+
expired_ack_ids.add(req.ack_id)
|
| 1204 |
+
return expired_ack_ids
|
| 1205 |
+
else:
|
| 1206 |
+
items: List[requests.ModAckRequest] = []
|
| 1207 |
+
if self._client.open_telemetry_enabled:
|
| 1208 |
+
for ack_id, data in zip(ack_ids, opentelemetry_data):
|
| 1209 |
+
assert data is not None
|
| 1210 |
+
items.append(
|
| 1211 |
+
requests.ModAckRequest(
|
| 1212 |
+
ack_id,
|
| 1213 |
+
self.ack_deadline,
|
| 1214 |
+
None,
|
| 1215 |
+
data,
|
| 1216 |
+
)
|
| 1217 |
+
)
|
| 1218 |
+
else:
|
| 1219 |
+
items = [
|
| 1220 |
+
requests.ModAckRequest(ack_id, self.ack_deadline, None)
|
| 1221 |
+
for ack_id in ack_ids
|
| 1222 |
+
]
|
| 1223 |
+
assert self._dispatcher is not None
|
| 1224 |
+
self._dispatcher.modify_ack_deadline(items, ack_deadline)
|
| 1225 |
+
if modack_span:
|
| 1226 |
+
modack_span.end()
|
| 1227 |
+
return set()
|
| 1228 |
+
|
| 1229 |
+
def _exactly_once_delivery_enabled(self) -> bool:
|
| 1230 |
+
"""Whether exactly-once delivery is enabled for the subscription."""
|
| 1231 |
+
with self._exactly_once_enabled_lock:
|
| 1232 |
+
return self._exactly_once_enabled
|
| 1233 |
+
|
| 1234 |
+
def _on_response(self, response: gapic_types.StreamingPullResponse) -> None:
|
| 1235 |
+
"""Process all received Pub/Sub messages.
|
| 1236 |
+
|
| 1237 |
+
For each message, send a modified acknowledgment request to the
|
| 1238 |
+
server. This prevents expiration of the message due to buffering by
|
| 1239 |
+
gRPC or proxy/firewall. This makes the server and client expiration
|
| 1240 |
+
timer closer to each other thus preventing the message being
|
| 1241 |
+
redelivered multiple times.
|
| 1242 |
+
|
| 1243 |
+
After the messages have all had their ack deadline updated, execute
|
| 1244 |
+
the callback for each message using the executor.
|
| 1245 |
+
"""
|
| 1246 |
+
if response is None:
|
| 1247 |
+
_LOGGER.debug(
|
| 1248 |
+
"Response callback invoked with None, likely due to a "
|
| 1249 |
+
"transport shutdown."
|
| 1250 |
+
)
|
| 1251 |
+
return
|
| 1252 |
+
|
| 1253 |
+
# IMPORTANT: Circumvent the wrapper class and operate on the raw underlying
|
| 1254 |
+
# protobuf message to significantly gain on attribute access performance.
|
| 1255 |
+
received_messages = response._pb.received_messages
|
| 1256 |
+
|
| 1257 |
+
subscribe_opentelemetry: List[SubscribeOpenTelemetry] = []
|
| 1258 |
+
if self._client.open_telemetry_enabled:
|
| 1259 |
+
for received_message in received_messages:
|
| 1260 |
+
opentelemetry_data = SubscribeOpenTelemetry(received_message.message)
|
| 1261 |
+
opentelemetry_data.start_subscribe_span(
|
| 1262 |
+
self._subscription,
|
| 1263 |
+
response.subscription_properties.exactly_once_delivery_enabled,
|
| 1264 |
+
received_message.ack_id,
|
| 1265 |
+
received_message.delivery_attempt,
|
| 1266 |
+
)
|
| 1267 |
+
subscribe_opentelemetry.append(opentelemetry_data)
|
| 1268 |
+
|
| 1269 |
+
_LOGGER.debug(
|
| 1270 |
+
"Processing %s received message(s), currently on hold %s (bytes %s).",
|
| 1271 |
+
len(received_messages),
|
| 1272 |
+
self._messages_on_hold.size,
|
| 1273 |
+
self._on_hold_bytes,
|
| 1274 |
+
)
|
| 1275 |
+
|
| 1276 |
+
with self._exactly_once_enabled_lock:
|
| 1277 |
+
if (
|
| 1278 |
+
response.subscription_properties.exactly_once_delivery_enabled
|
| 1279 |
+
!= self._exactly_once_enabled
|
| 1280 |
+
):
|
| 1281 |
+
self._exactly_once_enabled = (
|
| 1282 |
+
response.subscription_properties.exactly_once_delivery_enabled
|
| 1283 |
+
)
|
| 1284 |
+
# Update ack_deadline, whose minimum depends on self._exactly_once_enabled
|
| 1285 |
+
# This method acquires the self._ack_deadline_lock lock.
|
| 1286 |
+
self._obtain_ack_deadline(maybe_update=True)
|
| 1287 |
+
self._send_new_ack_deadline = True
|
| 1288 |
+
|
| 1289 |
+
# Immediately (i.e. without waiting for the auto lease management)
|
| 1290 |
+
# modack the messages we received, as this tells the server that we've
|
| 1291 |
+
# received them.
|
| 1292 |
+
ack_id_gen = (message.ack_id for message in received_messages)
|
| 1293 |
+
expired_ack_ids = self._send_lease_modacks(
|
| 1294 |
+
ack_id_gen,
|
| 1295 |
+
self.ack_deadline,
|
| 1296 |
+
subscribe_opentelemetry,
|
| 1297 |
+
warn_on_invalid=False,
|
| 1298 |
+
receipt_modack=True,
|
| 1299 |
+
)
|
| 1300 |
+
|
| 1301 |
+
if len(expired_ack_ids):
|
| 1302 |
+
_EXPIRY_LOGGER.debug(
|
| 1303 |
+
"ack ids %s were dropped as they have already expired.", expired_ack_ids
|
| 1304 |
+
)
|
| 1305 |
+
|
| 1306 |
+
with self._pause_resume_lock:
|
| 1307 |
+
if self._scheduler is None or self._leaser is None:
|
| 1308 |
+
_LOGGER.debug(
|
| 1309 |
+
f"self._scheduler={self._scheduler} or self._leaser={self._leaser} is None. Stopping further processing."
|
| 1310 |
+
)
|
| 1311 |
+
return
|
| 1312 |
+
|
| 1313 |
+
i: int = 0
|
| 1314 |
+
for received_message in received_messages:
|
| 1315 |
+
if (
|
| 1316 |
+
not self._exactly_once_delivery_enabled()
|
| 1317 |
+
or received_message.ack_id not in expired_ack_ids
|
| 1318 |
+
):
|
| 1319 |
+
message = google.cloud.pubsub_v1.subscriber.message.Message(
|
| 1320 |
+
received_message.message,
|
| 1321 |
+
received_message.ack_id,
|
| 1322 |
+
received_message.delivery_attempt,
|
| 1323 |
+
self._scheduler.queue,
|
| 1324 |
+
self._exactly_once_delivery_enabled,
|
| 1325 |
+
)
|
| 1326 |
+
if self._client.open_telemetry_enabled:
|
| 1327 |
+
message.opentelemetry_data = subscribe_opentelemetry[i]
|
| 1328 |
+
i = i + 1
|
| 1329 |
+
self._messages_on_hold.put(message)
|
| 1330 |
+
self._on_hold_bytes += message.size
|
| 1331 |
+
req = requests.LeaseRequest(
|
| 1332 |
+
ack_id=message.ack_id,
|
| 1333 |
+
byte_size=message.size,
|
| 1334 |
+
ordering_key=message.ordering_key,
|
| 1335 |
+
opentelemetry_data=message.opentelemetry_data,
|
| 1336 |
+
)
|
| 1337 |
+
self._leaser.add([req])
|
| 1338 |
+
|
| 1339 |
+
self._maybe_release_messages()
|
| 1340 |
+
|
| 1341 |
+
self.maybe_pause_consumer()
|
| 1342 |
+
|
| 1343 |
+
def _on_fatal_exception(self, exception: BaseException) -> None:
|
| 1344 |
+
"""
|
| 1345 |
+
Called whenever `self.consumer` receives a non-retryable exception.
|
| 1346 |
+
We close the manager on such non-retryable cases.
|
| 1347 |
+
"""
|
| 1348 |
+
_LOGGER.info(
|
| 1349 |
+
"Streaming pull terminating after receiving non-recoverable error: %s",
|
| 1350 |
+
exception,
|
| 1351 |
+
)
|
| 1352 |
+
self.close(exception)
|
| 1353 |
+
|
| 1354 |
+
def _should_recover(self, exception: BaseException) -> bool:
|
| 1355 |
+
"""Determine if an error on the RPC stream should be recovered.
|
| 1356 |
+
|
| 1357 |
+
If the exception is one of the retryable exceptions, this will signal
|
| 1358 |
+
to the consumer thread that it should "recover" from the failure.
|
| 1359 |
+
|
| 1360 |
+
This will cause the stream to exit when it returns :data:`False`.
|
| 1361 |
+
|
| 1362 |
+
Returns:
|
| 1363 |
+
Indicates if the caller should recover or shut down.
|
| 1364 |
+
Will be :data:`True` if the ``exception`` is "acceptable", i.e.
|
| 1365 |
+
in a list of retryable / idempotent exceptions.
|
| 1366 |
+
"""
|
| 1367 |
+
exception = _wrap_as_exception(exception)
|
| 1368 |
+
# If this is in the list of idempotent exceptions, then we want to
|
| 1369 |
+
# recover.
|
| 1370 |
+
if isinstance(exception, _RETRYABLE_STREAM_ERRORS):
|
| 1371 |
+
_STREAMS_LOGGER.debug(
|
| 1372 |
+
"Observed recoverable stream error %s, reopening stream", exception
|
| 1373 |
+
)
|
| 1374 |
+
return True
|
| 1375 |
+
_STREAMS_LOGGER.debug(
|
| 1376 |
+
"Observed non-recoverable stream error %s, shutting down stream", exception
|
| 1377 |
+
)
|
| 1378 |
+
return False
|
| 1379 |
+
|
| 1380 |
+
def _should_terminate(self, exception: BaseException) -> bool:
|
| 1381 |
+
"""Determine if an error on the RPC stream should be terminated.
|
| 1382 |
+
|
| 1383 |
+
If the exception is one of the terminating exceptions, this will signal
|
| 1384 |
+
to the consumer thread that it should terminate.
|
| 1385 |
+
|
| 1386 |
+
This will cause the stream to exit when it returns :data:`True`.
|
| 1387 |
+
|
| 1388 |
+
Returns:
|
| 1389 |
+
Indicates if the caller should terminate or attempt recovery.
|
| 1390 |
+
Will be :data:`True` if the ``exception`` is "acceptable", i.e.
|
| 1391 |
+
in a list of terminating exceptions.
|
| 1392 |
+
"""
|
| 1393 |
+
exception = _wrap_as_exception(exception)
|
| 1394 |
+
is_api_error = isinstance(exception, exceptions.GoogleAPICallError)
|
| 1395 |
+
# Terminate any non-API errors, or non-retryable errors (permission denied, unauthorized, etc.)
|
| 1396 |
+
if not is_api_error or isinstance(exception, _TERMINATING_STREAM_ERRORS):
|
| 1397 |
+
_STREAMS_LOGGER.debug(
|
| 1398 |
+
"Observed terminating stream error %s, shutting down stream", exception
|
| 1399 |
+
)
|
| 1400 |
+
return True
|
| 1401 |
+
_STREAMS_LOGGER.debug(
|
| 1402 |
+
"Observed non-terminating stream error %s, attempting to reopen", exception
|
| 1403 |
+
)
|
| 1404 |
+
return False
|
| 1405 |
+
|
| 1406 |
+
def _on_rpc_done(self, future: Any) -> None:
|
| 1407 |
+
"""Triggered whenever the underlying RPC terminates without recovery.
|
| 1408 |
+
|
| 1409 |
+
This is typically triggered from one of two threads: the background
|
| 1410 |
+
consumer thread (when calling ``recv()`` produces a non-recoverable
|
| 1411 |
+
error) or the grpc management thread (when cancelling the RPC).
|
| 1412 |
+
|
| 1413 |
+
This method is *non-blocking*. It will start another thread to deal
|
| 1414 |
+
with shutting everything down. This is to prevent blocking in the
|
| 1415 |
+
background consumer and preventing it from being ``joined()``.
|
| 1416 |
+
"""
|
| 1417 |
+
_LOGGER.debug("RPC termination has signaled streaming pull manager shutdown.")
|
| 1418 |
+
error = _wrap_as_exception(future)
|
| 1419 |
+
thread = threading.Thread(
|
| 1420 |
+
name=_RPC_ERROR_THREAD_NAME, target=self._shutdown, kwargs={"reason": error}
|
| 1421 |
+
)
|
| 1422 |
+
thread.daemon = True
|
| 1423 |
+
thread.start()
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/client.py
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
import os
|
| 18 |
+
import sys
|
| 19 |
+
import typing
|
| 20 |
+
import warnings
|
| 21 |
+
from typing import Any, Callable, Optional, Sequence, Union, cast
|
| 22 |
+
|
| 23 |
+
from google.auth.credentials import AnonymousCredentials # type: ignore
|
| 24 |
+
from google.oauth2 import service_account # type: ignore
|
| 25 |
+
|
| 26 |
+
from google.cloud.pubsub_v1 import types
|
| 27 |
+
from google.cloud.pubsub_v1.subscriber import futures
|
| 28 |
+
from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager
|
| 29 |
+
from google.pubsub_v1 import gapic_version as package_version
|
| 30 |
+
from google.pubsub_v1.services.subscriber import client as subscriber_client
|
| 31 |
+
|
| 32 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 33 |
+
from google.cloud.pubsub_v1 import subscriber
|
| 34 |
+
from google.pubsub_v1.services.subscriber.transports.grpc import (
|
| 35 |
+
SubscriberGrpcTransport,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
__version__ = package_version.__version__
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class Client(subscriber_client.SubscriberClient):
|
| 42 |
+
"""A subscriber client for Google Cloud Pub/Sub.
|
| 43 |
+
|
| 44 |
+
This creates an object that is capable of subscribing to messages.
|
| 45 |
+
Generally, you can instantiate this client with no arguments, and you
|
| 46 |
+
get sensible defaults.
|
| 47 |
+
|
| 48 |
+
Args:
|
| 49 |
+
kwargs: Any additional arguments provided are sent as keyword
|
| 50 |
+
keyword arguments to the underlying
|
| 51 |
+
:class:`~google.cloud.pubsub_v1.gapic.subscriber_client.SubscriberClient`.
|
| 52 |
+
Generally you should not need to set additional keyword
|
| 53 |
+
arguments. Optionally, regional endpoints can be set via
|
| 54 |
+
``client_options`` that takes a single key-value pair that
|
| 55 |
+
defines the endpoint.
|
| 56 |
+
|
| 57 |
+
Example:
|
| 58 |
+
|
| 59 |
+
.. code-block:: python
|
| 60 |
+
|
| 61 |
+
from google.cloud import pubsub_v1
|
| 62 |
+
|
| 63 |
+
subscriber_client = pubsub_v1.SubscriberClient(
|
| 64 |
+
# Optional
|
| 65 |
+
client_options = {
|
| 66 |
+
"api_endpoint": REGIONAL_ENDPOINT
|
| 67 |
+
}
|
| 68 |
+
)
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
def __init__(
|
| 72 |
+
self,
|
| 73 |
+
subscriber_options: Union[types.SubscriberOptions, Sequence] = (),
|
| 74 |
+
**kwargs: Any,
|
| 75 |
+
):
|
| 76 |
+
assert (
|
| 77 |
+
isinstance(subscriber_options, types.SubscriberOptions)
|
| 78 |
+
or len(subscriber_options) == 0
|
| 79 |
+
), "subscriber_options must be of type SubscriberOptions or an empty sequence."
|
| 80 |
+
|
| 81 |
+
# Sanity check: Is our goal to use the emulator?
|
| 82 |
+
# If so, create a grpc insecure channel with the emulator host
|
| 83 |
+
# as the target.
|
| 84 |
+
# TODO(https://github.com/googleapis/python-pubsub/issues/1349): Move the emulator
|
| 85 |
+
# code below to test files.
|
| 86 |
+
if os.environ.get("PUBSUB_EMULATOR_HOST"):
|
| 87 |
+
kwargs["client_options"] = {
|
| 88 |
+
"api_endpoint": os.environ.get("PUBSUB_EMULATOR_HOST")
|
| 89 |
+
}
|
| 90 |
+
# Configure credentials directly to transport, if provided.
|
| 91 |
+
if "transport" not in kwargs:
|
| 92 |
+
kwargs["credentials"] = AnonymousCredentials()
|
| 93 |
+
|
| 94 |
+
# Instantiate the underlying GAPIC client.
|
| 95 |
+
super().__init__(**kwargs)
|
| 96 |
+
self._target = self._transport._host
|
| 97 |
+
self._closed = False
|
| 98 |
+
|
| 99 |
+
self.subscriber_options = types.SubscriberOptions(*subscriber_options)
|
| 100 |
+
|
| 101 |
+
# Set / override Open Telemetry option.
|
| 102 |
+
self._open_telemetry_enabled = (
|
| 103 |
+
self.subscriber_options.enable_open_telemetry_tracing
|
| 104 |
+
)
|
| 105 |
+
# OpenTelemetry features used by the library are not supported in Python versions <= 3.7.
|
| 106 |
+
# Refer https://github.com/open-telemetry/opentelemetry-python/issues/3993#issuecomment-2211976389
|
| 107 |
+
if (
|
| 108 |
+
self.subscriber_options.enable_open_telemetry_tracing
|
| 109 |
+
and sys.version_info.major == 3
|
| 110 |
+
and sys.version_info.minor < 8
|
| 111 |
+
):
|
| 112 |
+
warnings.warn(
|
| 113 |
+
message="Open Telemetry for Python version 3.7 or lower is not supported. Disabling Open Telemetry tracing.",
|
| 114 |
+
category=RuntimeWarning,
|
| 115 |
+
)
|
| 116 |
+
self._open_telemetry_enabled = False
|
| 117 |
+
|
| 118 |
+
@property
|
| 119 |
+
def open_telemetry_enabled(self) -> bool:
|
| 120 |
+
"""
|
| 121 |
+
Returns True if Open Telemetry is enabled. False otherwise.
|
| 122 |
+
"""
|
| 123 |
+
return self._open_telemetry_enabled # pragma: NO COVER
|
| 124 |
+
|
| 125 |
+
@classmethod
|
| 126 |
+
def from_service_account_file( # type: ignore[override]
|
| 127 |
+
cls, filename: str, **kwargs: Any
|
| 128 |
+
) -> "Client":
|
| 129 |
+
"""Creates an instance of this client using the provided credentials
|
| 130 |
+
file.
|
| 131 |
+
|
| 132 |
+
Args:
|
| 133 |
+
filename: The path to the service account private key json file.
|
| 134 |
+
kwargs: Additional arguments to pass to the constructor.
|
| 135 |
+
|
| 136 |
+
Returns:
|
| 137 |
+
A Subscriber :class:`~google.cloud.pubsub_v1.subscriber.client.Client`
|
| 138 |
+
instance that is the constructed client.
|
| 139 |
+
"""
|
| 140 |
+
credentials = service_account.Credentials.from_service_account_file(filename)
|
| 141 |
+
kwargs["credentials"] = credentials
|
| 142 |
+
return cls(**kwargs)
|
| 143 |
+
|
| 144 |
+
from_service_account_json = from_service_account_file # type: ignore[assignment]
|
| 145 |
+
|
| 146 |
+
@property
|
| 147 |
+
def target(self) -> str:
|
| 148 |
+
"""Return the target (where the API is).
|
| 149 |
+
|
| 150 |
+
Returns:
|
| 151 |
+
The location of the API.
|
| 152 |
+
"""
|
| 153 |
+
return self._target
|
| 154 |
+
|
| 155 |
+
@property
|
| 156 |
+
def closed(self) -> bool:
|
| 157 |
+
"""Return whether the client has been closed and cannot be used anymore.
|
| 158 |
+
|
| 159 |
+
.. versionadded:: 2.8.0
|
| 160 |
+
"""
|
| 161 |
+
return self._closed
|
| 162 |
+
|
| 163 |
+
@property
|
| 164 |
+
def api(self):
|
| 165 |
+
"""The underlying gapic API client.
|
| 166 |
+
|
| 167 |
+
.. versionchanged:: 2.10.0
|
| 168 |
+
Instead of a GAPIC ``SubscriberClient`` client instance, this property is a
|
| 169 |
+
proxy object to it with the same interface.
|
| 170 |
+
|
| 171 |
+
.. deprecated:: 2.10.0
|
| 172 |
+
Use the GAPIC methods and properties on the client instance directly
|
| 173 |
+
instead of through the :attr:`api` attribute.
|
| 174 |
+
"""
|
| 175 |
+
msg = (
|
| 176 |
+
'The "api" property only exists for backward compatibility, access its '
|
| 177 |
+
'attributes directly thorugh the client instance (e.g. "client.foo" '
|
| 178 |
+
'instead of "client.api.foo").'
|
| 179 |
+
)
|
| 180 |
+
warnings.warn(msg, category=DeprecationWarning)
|
| 181 |
+
return super()
|
| 182 |
+
|
| 183 |
+
def subscribe(
|
| 184 |
+
self,
|
| 185 |
+
subscription: str,
|
| 186 |
+
callback: Callable[["subscriber.message.Message"], Any],
|
| 187 |
+
flow_control: Union[types.FlowControl, Sequence] = (),
|
| 188 |
+
scheduler: Optional["subscriber.scheduler.ThreadScheduler"] = None,
|
| 189 |
+
use_legacy_flow_control: bool = False,
|
| 190 |
+
await_callbacks_on_shutdown: bool = False,
|
| 191 |
+
) -> futures.StreamingPullFuture:
|
| 192 |
+
"""Asynchronously start receiving messages on a given subscription.
|
| 193 |
+
|
| 194 |
+
This method starts a background thread to begin pulling messages from
|
| 195 |
+
a Pub/Sub subscription and scheduling them to be processed using the
|
| 196 |
+
provided ``callback``.
|
| 197 |
+
|
| 198 |
+
The ``callback`` will be called with an individual
|
| 199 |
+
:class:`google.cloud.pubsub_v1.subscriber.message.Message`. It is the
|
| 200 |
+
responsibility of the callback to either call ``ack()`` or ``nack()``
|
| 201 |
+
on the message when it finished processing. If an exception occurs in
|
| 202 |
+
the callback during processing, the exception is logged and the message
|
| 203 |
+
is ``nack()`` ed.
|
| 204 |
+
|
| 205 |
+
The ``flow_control`` argument can be used to control the rate of at
|
| 206 |
+
which messages are pulled. The settings are relatively conservative by
|
| 207 |
+
default to prevent "message hoarding" - a situation where the client
|
| 208 |
+
pulls a large number of messages but can not process them fast enough
|
| 209 |
+
leading it to "starve" other clients of messages. Increasing these
|
| 210 |
+
settings may lead to faster throughput for messages that do not take
|
| 211 |
+
a long time to process.
|
| 212 |
+
|
| 213 |
+
The ``use_legacy_flow_control`` argument disables enforcing flow control
|
| 214 |
+
settings at the Cloud Pub/Sub server, and only the client side flow control
|
| 215 |
+
will be enforced.
|
| 216 |
+
|
| 217 |
+
This method starts the receiver in the background and returns a
|
| 218 |
+
*Future* representing its execution. Waiting on the future (calling
|
| 219 |
+
``result()``) will block forever or until a non-recoverable error
|
| 220 |
+
is encountered (such as loss of network connectivity). Cancelling the
|
| 221 |
+
future will signal the process to shutdown gracefully and exit.
|
| 222 |
+
|
| 223 |
+
.. note:: This uses Pub/Sub's *streaming pull* feature. This feature
|
| 224 |
+
properties that may be surprising. Please take a look at
|
| 225 |
+
https://cloud.google.com/pubsub/docs/pull#streamingpull for
|
| 226 |
+
more details on how streaming pull behaves compared to the
|
| 227 |
+
synchronous pull method.
|
| 228 |
+
|
| 229 |
+
Example:
|
| 230 |
+
|
| 231 |
+
.. code-block:: python
|
| 232 |
+
|
| 233 |
+
from google.cloud import pubsub_v1
|
| 234 |
+
|
| 235 |
+
subscriber_client = pubsub_v1.SubscriberClient()
|
| 236 |
+
|
| 237 |
+
# existing subscription
|
| 238 |
+
subscription = subscriber_client.subscription_path(
|
| 239 |
+
'my-project-id', 'my-subscription')
|
| 240 |
+
|
| 241 |
+
def callback(message):
|
| 242 |
+
print(message)
|
| 243 |
+
message.ack()
|
| 244 |
+
|
| 245 |
+
future = subscriber_client.subscribe(
|
| 246 |
+
subscription, callback)
|
| 247 |
+
|
| 248 |
+
try:
|
| 249 |
+
future.result()
|
| 250 |
+
except KeyboardInterrupt:
|
| 251 |
+
future.cancel() # Trigger the shutdown.
|
| 252 |
+
future.result() # Block until the shutdown is complete.
|
| 253 |
+
|
| 254 |
+
Args:
|
| 255 |
+
subscription:
|
| 256 |
+
The name of the subscription. The subscription should have already been
|
| 257 |
+
created (for example, by using :meth:`create_subscription`).
|
| 258 |
+
callback:
|
| 259 |
+
The callback function. This function receives the message as
|
| 260 |
+
its only argument and will be called from a different thread/
|
| 261 |
+
process depending on the scheduling strategy.
|
| 262 |
+
flow_control:
|
| 263 |
+
The flow control settings. Use this to prevent situations where you are
|
| 264 |
+
inundated with too many messages at once.
|
| 265 |
+
scheduler:
|
| 266 |
+
An optional *scheduler* to use when executing the callback. This
|
| 267 |
+
controls how callbacks are executed concurrently. This object must not
|
| 268 |
+
be shared across multiple ``SubscriberClient`` instances.
|
| 269 |
+
use_legacy_flow_control (bool):
|
| 270 |
+
If set to ``True``, flow control at the Cloud Pub/Sub server is disabled,
|
| 271 |
+
though client-side flow control is still enabled. If set to ``False``
|
| 272 |
+
(default), both server-side and client-side flow control are enabled.
|
| 273 |
+
await_callbacks_on_shutdown:
|
| 274 |
+
If ``True``, after canceling the returned future, the latter's
|
| 275 |
+
``result()`` method will block until the background stream and its
|
| 276 |
+
helper threads have been terminated, and all currently executing message
|
| 277 |
+
callbacks are done processing.
|
| 278 |
+
|
| 279 |
+
If ``False`` (default), the returned future's ``result()`` method will
|
| 280 |
+
not block after canceling the future. The method will instead return
|
| 281 |
+
immediately after the background stream and its helper threads have been
|
| 282 |
+
terminated, but some of the message callback threads might still be
|
| 283 |
+
running at that point.
|
| 284 |
+
|
| 285 |
+
Returns:
|
| 286 |
+
A future instance that can be used to manage the background stream.
|
| 287 |
+
"""
|
| 288 |
+
flow_control = types.FlowControl(*flow_control)
|
| 289 |
+
|
| 290 |
+
manager = streaming_pull_manager.StreamingPullManager(
|
| 291 |
+
self,
|
| 292 |
+
subscription,
|
| 293 |
+
flow_control=flow_control,
|
| 294 |
+
scheduler=scheduler,
|
| 295 |
+
use_legacy_flow_control=use_legacy_flow_control,
|
| 296 |
+
await_callbacks_on_shutdown=await_callbacks_on_shutdown,
|
| 297 |
+
)
|
| 298 |
+
|
| 299 |
+
future = futures.StreamingPullFuture(manager)
|
| 300 |
+
|
| 301 |
+
manager.open(callback=callback, on_callback_error=future.set_exception)
|
| 302 |
+
|
| 303 |
+
return future
|
| 304 |
+
|
| 305 |
+
def close(self) -> None:
|
| 306 |
+
"""Close the underlying channel to release socket resources.
|
| 307 |
+
|
| 308 |
+
After a channel has been closed, the client instance cannot be used
|
| 309 |
+
anymore.
|
| 310 |
+
|
| 311 |
+
This method is idempotent.
|
| 312 |
+
"""
|
| 313 |
+
transport = cast("SubscriberGrpcTransport", self._transport)
|
| 314 |
+
transport.grpc_channel.close()
|
| 315 |
+
self._closed = True
|
| 316 |
+
|
| 317 |
+
def __enter__(self) -> "Client":
|
| 318 |
+
if self._closed:
|
| 319 |
+
raise RuntimeError("Closed subscriber cannot be used as context manager.")
|
| 320 |
+
return self
|
| 321 |
+
|
| 322 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 323 |
+
self.close()
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/exceptions.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
from enum import Enum
|
| 18 |
+
from typing import Optional
|
| 19 |
+
|
| 20 |
+
from google.api_core.exceptions import GoogleAPICallError
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class AcknowledgeStatus(Enum):
|
| 24 |
+
SUCCESS = 1
|
| 25 |
+
PERMISSION_DENIED = 2
|
| 26 |
+
FAILED_PRECONDITION = 3
|
| 27 |
+
INVALID_ACK_ID = 4
|
| 28 |
+
OTHER = 5
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class AcknowledgeError(GoogleAPICallError):
|
| 32 |
+
"""Error during ack/modack/nack operation on exactly-once-enabled subscription."""
|
| 33 |
+
|
| 34 |
+
def __init__(self, error_code: AcknowledgeStatus, info: Optional[str]):
|
| 35 |
+
self.error_code = error_code
|
| 36 |
+
self.info = info
|
| 37 |
+
message = None
|
| 38 |
+
if info:
|
| 39 |
+
message = str(self.error_code) + " : " + str(self.info)
|
| 40 |
+
else:
|
| 41 |
+
message = str(self.error_code)
|
| 42 |
+
super(AcknowledgeError, self).__init__(message)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
__all__ = ("AcknowledgeError",)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/futures.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
import typing
|
| 18 |
+
from typing import Any, Union
|
| 19 |
+
|
| 20 |
+
from google.cloud.pubsub_v1 import futures
|
| 21 |
+
from google.cloud.pubsub_v1.subscriber.exceptions import AcknowledgeStatus
|
| 22 |
+
|
| 23 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 24 |
+
from google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager import (
|
| 25 |
+
StreamingPullManager,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class StreamingPullFuture(futures.Future):
|
| 30 |
+
"""Represents a process that asynchronously performs streaming pull and
|
| 31 |
+
schedules messages to be processed.
|
| 32 |
+
|
| 33 |
+
This future is resolved when the process is stopped (via :meth:`cancel`) or
|
| 34 |
+
if it encounters an unrecoverable error. Calling `.result()` will cause
|
| 35 |
+
the calling thread to block indefinitely.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
def __init__(self, manager: "StreamingPullManager"):
|
| 39 |
+
super(StreamingPullFuture, self).__init__()
|
| 40 |
+
self.__manager = manager
|
| 41 |
+
self.__manager.add_close_callback(self._on_close_callback)
|
| 42 |
+
self.__cancelled = False
|
| 43 |
+
|
| 44 |
+
def _on_close_callback(self, manager: "StreamingPullManager", result: Any):
|
| 45 |
+
if self.done():
|
| 46 |
+
# The future has already been resolved in a different thread,
|
| 47 |
+
# nothing to do on the streaming pull manager shutdown.
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
if result is None:
|
| 51 |
+
self.set_result(True)
|
| 52 |
+
else:
|
| 53 |
+
self.set_exception(result)
|
| 54 |
+
|
| 55 |
+
def cancel(self) -> bool:
|
| 56 |
+
"""Stops pulling messages and shutdowns the background thread consuming
|
| 57 |
+
messages.
|
| 58 |
+
|
| 59 |
+
The method always returns ``True``, as the shutdown is always initiated.
|
| 60 |
+
However, if the background stream is already being shut down or the shutdown
|
| 61 |
+
has completed, this method is a no-op.
|
| 62 |
+
|
| 63 |
+
.. versionchanged:: 2.4.1
|
| 64 |
+
The method does not block anymore, it just triggers the shutdown and returns
|
| 65 |
+
immediately. To block until the background stream is terminated, call
|
| 66 |
+
:meth:`result()` after cancelling the future.
|
| 67 |
+
|
| 68 |
+
.. versionchanged:: 2.10.0
|
| 69 |
+
The method always returns ``True`` instead of ``None``.
|
| 70 |
+
"""
|
| 71 |
+
# NOTE: We circumvent the base future's self._state to track the cancellation
|
| 72 |
+
# state, as this state has different meaning with streaming pull futures.
|
| 73 |
+
self.__cancelled = True
|
| 74 |
+
self.__manager.close()
|
| 75 |
+
return True
|
| 76 |
+
|
| 77 |
+
def cancelled(self) -> bool:
|
| 78 |
+
"""
|
| 79 |
+
Returns:
|
| 80 |
+
``True`` if the subscription has been cancelled.
|
| 81 |
+
"""
|
| 82 |
+
return self.__cancelled
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class Future(futures.Future):
|
| 86 |
+
"""This future object is for subscribe-side calls.
|
| 87 |
+
|
| 88 |
+
Calling :meth:`result` will resolve the future by returning the message
|
| 89 |
+
ID, unless an error occurs.
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
def cancel(self) -> bool:
|
| 93 |
+
"""Actions in Pub/Sub generally may not be canceled.
|
| 94 |
+
|
| 95 |
+
This method always returns ``False``.
|
| 96 |
+
"""
|
| 97 |
+
return False
|
| 98 |
+
|
| 99 |
+
def cancelled(self) -> bool:
|
| 100 |
+
"""Actions in Pub/Sub generally may not be canceled.
|
| 101 |
+
|
| 102 |
+
This method always returns ``False``.
|
| 103 |
+
"""
|
| 104 |
+
return False
|
| 105 |
+
|
| 106 |
+
def result(self, timeout: Union[int, float, None] = None) -> AcknowledgeStatus:
|
| 107 |
+
"""Return a success code or raise an exception.
|
| 108 |
+
|
| 109 |
+
This blocks until the operation completes successfully and
|
| 110 |
+
returns the error code unless an exception is raised.
|
| 111 |
+
|
| 112 |
+
Args:
|
| 113 |
+
timeout: The number of seconds before this call
|
| 114 |
+
times out and raises TimeoutError.
|
| 115 |
+
|
| 116 |
+
Returns:
|
| 117 |
+
AcknowledgeStatus.SUCCESS if the operation succeeded.
|
| 118 |
+
|
| 119 |
+
Raises:
|
| 120 |
+
concurrent.futures.TimeoutError: If the request times out.
|
| 121 |
+
AcknowledgeError: If the operation did not succeed for another
|
| 122 |
+
reason.
|
| 123 |
+
"""
|
| 124 |
+
return super().result(timeout=timeout)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/message.py
ADDED
|
@@ -0,0 +1,563 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
import datetime as dt
|
| 18 |
+
import json
|
| 19 |
+
import logging
|
| 20 |
+
import math
|
| 21 |
+
import time
|
| 22 |
+
import typing
|
| 23 |
+
from typing import Callable, Optional
|
| 24 |
+
|
| 25 |
+
from google.cloud.pubsub_v1.open_telemetry.subscribe_opentelemetry import (
|
| 26 |
+
SubscribeOpenTelemetry,
|
| 27 |
+
)
|
| 28 |
+
from google.cloud.pubsub_v1.subscriber import futures
|
| 29 |
+
from google.cloud.pubsub_v1.subscriber._protocol import requests
|
| 30 |
+
from google.cloud.pubsub_v1.subscriber.exceptions import AcknowledgeStatus
|
| 31 |
+
|
| 32 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 33 |
+
import datetime
|
| 34 |
+
import queue
|
| 35 |
+
|
| 36 |
+
from google.protobuf.internal import containers
|
| 37 |
+
|
| 38 |
+
from google.cloud.pubsub_v1 import types
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
_MESSAGE_REPR = """\
|
| 42 |
+
Message {{
|
| 43 |
+
data: {!r}
|
| 44 |
+
ordering_key: {!r}
|
| 45 |
+
attributes: {}
|
| 46 |
+
}}"""
|
| 47 |
+
|
| 48 |
+
_ACK_NACK_LOGGER = logging.getLogger("ack-nack")
|
| 49 |
+
|
| 50 |
+
_SUCCESS_FUTURE = futures.Future()
|
| 51 |
+
_SUCCESS_FUTURE.set_result(AcknowledgeStatus.SUCCESS)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _indent(lines: str, prefix: str = " ") -> str:
|
| 55 |
+
"""Indent some text.
|
| 56 |
+
|
| 57 |
+
Note that this is present as ``textwrap.indent``, but not in Python 2.
|
| 58 |
+
|
| 59 |
+
Args:
|
| 60 |
+
lines:
|
| 61 |
+
The newline delimited string to be indented.
|
| 62 |
+
prefix:
|
| 63 |
+
The prefix to indent each line with. Defaults to two spaces.
|
| 64 |
+
|
| 65 |
+
Returns:
|
| 66 |
+
The newly indented content.
|
| 67 |
+
"""
|
| 68 |
+
indented = []
|
| 69 |
+
for line in lines.split("\n"):
|
| 70 |
+
indented.append(prefix + line)
|
| 71 |
+
return "\n".join(indented)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class Message(object):
|
| 75 |
+
"""A representation of a single Pub/Sub message.
|
| 76 |
+
|
| 77 |
+
The common way to interact with
|
| 78 |
+
:class:`~.pubsub_v1.subscriber.message.Message` objects is to receive
|
| 79 |
+
them in callbacks on subscriptions; most users should never have a need
|
| 80 |
+
to instantiate them by hand. (The exception to this is if you are
|
| 81 |
+
implementing a custom subclass to
|
| 82 |
+
:class:`~.pubsub_v1.subscriber._consumer.Consumer`.)
|
| 83 |
+
|
| 84 |
+
Attributes:
|
| 85 |
+
message_id (str):
|
| 86 |
+
The message ID. In general, you should not need to use this directly.
|
| 87 |
+
data (bytes):
|
| 88 |
+
The data in the message. Note that this will be a :class:`bytes`,
|
| 89 |
+
not a text string.
|
| 90 |
+
attributes (MutableMapping[str, str]):
|
| 91 |
+
The attributes sent along with the message. See :attr:`attributes` for more
|
| 92 |
+
information on this type.
|
| 93 |
+
publish_time (google.protobuf.timestamp_pb2.Timestamp):
|
| 94 |
+
The time that this message was originally published.
|
| 95 |
+
opentelemetry_data (google.cloud.pubsub_v1.open_telemetry.subscribe_opentelemetry.SubscribeOpenTelemetry)
|
| 96 |
+
Open Telemetry data associated with this message. None if Open Telemetry is not enabled.
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
def __init__(
|
| 100 |
+
self,
|
| 101 |
+
message: "types.PubsubMessage._meta._pb", # type: ignore
|
| 102 |
+
ack_id: str,
|
| 103 |
+
delivery_attempt: int,
|
| 104 |
+
request_queue: "queue.Queue",
|
| 105 |
+
exactly_once_delivery_enabled_func: Callable[[], bool] = lambda: False,
|
| 106 |
+
):
|
| 107 |
+
"""Construct the Message.
|
| 108 |
+
|
| 109 |
+
.. note::
|
| 110 |
+
|
| 111 |
+
This class should not be constructed directly; it is the
|
| 112 |
+
responsibility of :class:`BasePolicy` subclasses to do so.
|
| 113 |
+
|
| 114 |
+
Args:
|
| 115 |
+
message (types.PubsubMessage._meta._pb):
|
| 116 |
+
The message received from Pub/Sub. For performance reasons it should be
|
| 117 |
+
the raw protobuf message normally wrapped by
|
| 118 |
+
:class:`~pubsub_v1.types.PubsubMessage`. A raw message can be obtained
|
| 119 |
+
from a :class:`~pubsub_v1.types.PubsubMessage` instance through the
|
| 120 |
+
latter's ``._pb`` attribute.
|
| 121 |
+
ack_id (str):
|
| 122 |
+
The ack_id received from Pub/Sub.
|
| 123 |
+
delivery_attempt (int):
|
| 124 |
+
The delivery attempt counter received from Pub/Sub if a DeadLetterPolicy
|
| 125 |
+
is set on the subscription, and zero otherwise.
|
| 126 |
+
request_queue (queue.Queue):
|
| 127 |
+
A queue provided by the policy that can accept requests; the policy is
|
| 128 |
+
responsible for handling those requests.
|
| 129 |
+
exactly_once_delivery_enabled_func (Callable[[], bool]):
|
| 130 |
+
A Callable that returns whether exactly-once delivery is currently-enabled. Defaults to a lambda that always returns False.
|
| 131 |
+
"""
|
| 132 |
+
self._message = message
|
| 133 |
+
self._ack_id = ack_id
|
| 134 |
+
self._delivery_attempt = delivery_attempt if delivery_attempt > 0 else None
|
| 135 |
+
self._request_queue = request_queue
|
| 136 |
+
self._exactly_once_delivery_enabled_func = exactly_once_delivery_enabled_func
|
| 137 |
+
self.message_id = message.message_id
|
| 138 |
+
|
| 139 |
+
# The instantiation time is the time that this message
|
| 140 |
+
# was received. Tracking this provides us a way to be smart about
|
| 141 |
+
# the default lease deadline.
|
| 142 |
+
self._received_timestamp = time.time()
|
| 143 |
+
|
| 144 |
+
# Store the message attributes directly to speed up attribute access, i.e.
|
| 145 |
+
# to avoid two lookups if self._message.<attribute> pattern was used in
|
| 146 |
+
# properties.
|
| 147 |
+
self._attributes = message.attributes
|
| 148 |
+
self._data = message.data
|
| 149 |
+
self._publish_time = dt.datetime.fromtimestamp(
|
| 150 |
+
message.publish_time.seconds + message.publish_time.nanos / 1e9,
|
| 151 |
+
tz=dt.timezone.utc,
|
| 152 |
+
)
|
| 153 |
+
self._ordering_key = message.ordering_key
|
| 154 |
+
self._size = message.ByteSize()
|
| 155 |
+
|
| 156 |
+
# None if Open Telemetry is disabled. Else contains OpenTelemetry data.
|
| 157 |
+
self._opentelemetry_data: Optional[SubscribeOpenTelemetry] = None
|
| 158 |
+
|
| 159 |
+
def __repr__(self):
|
| 160 |
+
# Get an abbreviated version of the data.
|
| 161 |
+
abbv_data = self._message.data
|
| 162 |
+
if len(abbv_data) > 50:
|
| 163 |
+
abbv_data = abbv_data[:50] + b"..."
|
| 164 |
+
|
| 165 |
+
pretty_attrs = json.dumps(
|
| 166 |
+
dict(self.attributes), indent=2, separators=(",", ": "), sort_keys=True
|
| 167 |
+
)
|
| 168 |
+
pretty_attrs = _indent(pretty_attrs)
|
| 169 |
+
# We don't actually want the first line indented.
|
| 170 |
+
pretty_attrs = pretty_attrs.lstrip()
|
| 171 |
+
return _MESSAGE_REPR.format(abbv_data, str(self.ordering_key), pretty_attrs)
|
| 172 |
+
|
| 173 |
+
@property
|
| 174 |
+
def opentelemetry_data(self):
|
| 175 |
+
return self._opentelemetry_data # pragma: NO COVER
|
| 176 |
+
|
| 177 |
+
@opentelemetry_data.setter
|
| 178 |
+
def opentelemetry_data(self, data):
|
| 179 |
+
self._opentelemetry_data = data # pragma: NO COVER
|
| 180 |
+
|
| 181 |
+
@property
|
| 182 |
+
def attributes(self) -> "containers.ScalarMap":
|
| 183 |
+
"""Return the attributes of the underlying Pub/Sub Message.
|
| 184 |
+
|
| 185 |
+
.. warning::
|
| 186 |
+
|
| 187 |
+
A ``ScalarMap`` behaves slightly differently than a
|
| 188 |
+
``dict``. For a Pub / Sub message this is a ``string->string`` map.
|
| 189 |
+
When trying to access a value via ``map['key']``, if the key is
|
| 190 |
+
not in the map, then the default value for the string type will
|
| 191 |
+
be returned, which is an empty string. It may be more intuitive
|
| 192 |
+
to just cast the map to a ``dict`` or to one use ``map.get``.
|
| 193 |
+
|
| 194 |
+
Returns:
|
| 195 |
+
containers.ScalarMap: The message's attributes. This is a
|
| 196 |
+
``dict``-like object provided by ``google.protobuf``.
|
| 197 |
+
"""
|
| 198 |
+
return self._attributes
|
| 199 |
+
|
| 200 |
+
@property
|
| 201 |
+
def data(self) -> bytes:
|
| 202 |
+
"""Return the data for the underlying Pub/Sub Message.
|
| 203 |
+
|
| 204 |
+
Returns:
|
| 205 |
+
bytes: The message data. This is always a bytestring; if you want
|
| 206 |
+
a text string, call :meth:`bytes.decode`.
|
| 207 |
+
"""
|
| 208 |
+
return self._data
|
| 209 |
+
|
| 210 |
+
@property
|
| 211 |
+
def publish_time(self) -> "datetime.datetime":
|
| 212 |
+
"""Return the time that the message was originally published.
|
| 213 |
+
|
| 214 |
+
Returns:
|
| 215 |
+
datetime.datetime: The date and time that the message was
|
| 216 |
+
published.
|
| 217 |
+
"""
|
| 218 |
+
return self._publish_time
|
| 219 |
+
|
| 220 |
+
@property
|
| 221 |
+
def ordering_key(self) -> str:
|
| 222 |
+
"""The ordering key used to publish the message."""
|
| 223 |
+
return self._ordering_key
|
| 224 |
+
|
| 225 |
+
@property
|
| 226 |
+
def size(self) -> int:
|
| 227 |
+
"""Return the size of the underlying message, in bytes."""
|
| 228 |
+
return self._size
|
| 229 |
+
|
| 230 |
+
@property
|
| 231 |
+
def ack_id(self) -> str:
|
| 232 |
+
"""the ID used to ack the message."""
|
| 233 |
+
return self._ack_id
|
| 234 |
+
|
| 235 |
+
@property
|
| 236 |
+
def delivery_attempt(self) -> Optional[int]:
|
| 237 |
+
"""The delivery attempt counter is 1 + (the sum of number of NACKs
|
| 238 |
+
and number of ack_deadline exceeds) for this message. It is set to None
|
| 239 |
+
if a DeadLetterPolicy is not set on the subscription.
|
| 240 |
+
|
| 241 |
+
A NACK is any call to ModifyAckDeadline with a 0 deadline. An ack_deadline
|
| 242 |
+
exceeds event is whenever a message is not acknowledged within
|
| 243 |
+
ack_deadline. Note that ack_deadline is initially
|
| 244 |
+
Subscription.ackDeadlineSeconds, but may get extended automatically by
|
| 245 |
+
the client library.
|
| 246 |
+
|
| 247 |
+
The first delivery of a given message will have this value as 1. The value
|
| 248 |
+
is calculated at best effort and is approximate.
|
| 249 |
+
|
| 250 |
+
Returns:
|
| 251 |
+
Optional[int]: The delivery attempt counter or ``None``.
|
| 252 |
+
"""
|
| 253 |
+
return self._delivery_attempt
|
| 254 |
+
|
| 255 |
+
def ack(self) -> None:
|
| 256 |
+
"""Acknowledge the given message.
|
| 257 |
+
|
| 258 |
+
Acknowledging a message in Pub/Sub means that you are done
|
| 259 |
+
with it, and it will not be delivered to this subscription again.
|
| 260 |
+
You should avoid acknowledging messages until you have
|
| 261 |
+
*finished* processing them, so that in the event of a failure,
|
| 262 |
+
you receive the message again.
|
| 263 |
+
|
| 264 |
+
.. warning::
|
| 265 |
+
Acks in Pub/Sub are best effort. You should always
|
| 266 |
+
ensure that your processing code is idempotent, as you may
|
| 267 |
+
receive any given message more than once. If you need strong
|
| 268 |
+
guarantees about acks and re-deliveres, enable exactly-once
|
| 269 |
+
delivery on your subscription and use the `ack_with_response`
|
| 270 |
+
method instead. Exactly once delivery is a preview feature.
|
| 271 |
+
For more details, see:
|
| 272 |
+
https://cloud.google.com/pubsub/docs/exactly-once-delivery."
|
| 273 |
+
|
| 274 |
+
"""
|
| 275 |
+
if self.opentelemetry_data:
|
| 276 |
+
self.opentelemetry_data.add_process_span_event("ack called")
|
| 277 |
+
self.opentelemetry_data.end_process_span()
|
| 278 |
+
time_to_ack = math.ceil(time.time() - self._received_timestamp)
|
| 279 |
+
self._request_queue.put(
|
| 280 |
+
requests.AckRequest(
|
| 281 |
+
message_id=self.message_id,
|
| 282 |
+
ack_id=self._ack_id,
|
| 283 |
+
byte_size=self.size,
|
| 284 |
+
time_to_ack=time_to_ack,
|
| 285 |
+
ordering_key=self.ordering_key,
|
| 286 |
+
future=None,
|
| 287 |
+
opentelemetry_data=self.opentelemetry_data,
|
| 288 |
+
)
|
| 289 |
+
)
|
| 290 |
+
_ACK_NACK_LOGGER.debug(
|
| 291 |
+
"Called ack for message (id=%s, ack_id=%s, ordering_key=%s)",
|
| 292 |
+
self.message_id,
|
| 293 |
+
self.ack_id,
|
| 294 |
+
self.ordering_key,
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
def ack_with_response(self) -> "futures.Future":
|
| 298 |
+
"""Acknowledge the given message.
|
| 299 |
+
|
| 300 |
+
Acknowledging a message in Pub/Sub means that you are done
|
| 301 |
+
with it, and it will not be delivered to this subscription again.
|
| 302 |
+
You should avoid acknowledging messages until you have
|
| 303 |
+
*finished* processing them, so that in the event of a failure,
|
| 304 |
+
you receive the message again.
|
| 305 |
+
|
| 306 |
+
If exactly-once delivery is NOT enabled on the subscription, the
|
| 307 |
+
future returns immediately with an AcknowledgeStatus.SUCCESS.
|
| 308 |
+
Since acks in Cloud Pub/Sub are best effort when exactly-once
|
| 309 |
+
delivery is disabled, the message may be re-delivered. Because
|
| 310 |
+
re-deliveries are possible, you should ensure that your processing
|
| 311 |
+
code is idempotent, as you may receive any given message more than
|
| 312 |
+
once.
|
| 313 |
+
|
| 314 |
+
If exactly-once delivery is enabled on the subscription, the
|
| 315 |
+
future returned by this method tracks the state of acknowledgement
|
| 316 |
+
operation. If the future completes successfully, the message is
|
| 317 |
+
guaranteed NOT to be re-delivered. Otherwise, the future will
|
| 318 |
+
contain an exception with more details about the failure and the
|
| 319 |
+
message may be re-delivered.
|
| 320 |
+
|
| 321 |
+
Exactly once delivery is a preview feature. For more details,
|
| 322 |
+
see https://cloud.google.com/pubsub/docs/exactly-once-delivery."
|
| 323 |
+
|
| 324 |
+
Returns:
|
| 325 |
+
futures.Future: A
|
| 326 |
+
:class:`~google.cloud.pubsub_v1.subscriber.futures.Future`
|
| 327 |
+
instance that conforms to Python Standard library's
|
| 328 |
+
:class:`~concurrent.futures.Future` interface (but not an
|
| 329 |
+
instance of that class). Call `result()` to get the result
|
| 330 |
+
of the operation; upon success, a
|
| 331 |
+
pubsub_v1.subscriber.exceptions.AcknowledgeStatus.SUCCESS
|
| 332 |
+
will be returned and upon an error, an
|
| 333 |
+
pubsub_v1.subscriber.exceptions.AcknowledgeError exception
|
| 334 |
+
will be thrown.
|
| 335 |
+
"""
|
| 336 |
+
_ACK_NACK_LOGGER.debug(
|
| 337 |
+
"Called ack for message (id=%s, ack_id=%s, ordering_key=%s, exactly_once=True)",
|
| 338 |
+
self.message_id,
|
| 339 |
+
self.ack_id,
|
| 340 |
+
self.ordering_key,
|
| 341 |
+
)
|
| 342 |
+
if self.opentelemetry_data:
|
| 343 |
+
self.opentelemetry_data.add_process_span_event("ack called")
|
| 344 |
+
self.opentelemetry_data.end_process_span()
|
| 345 |
+
req_future: Optional[futures.Future]
|
| 346 |
+
if self._exactly_once_delivery_enabled_func():
|
| 347 |
+
future = futures.Future()
|
| 348 |
+
req_future = future
|
| 349 |
+
else:
|
| 350 |
+
future = _SUCCESS_FUTURE
|
| 351 |
+
req_future = None
|
| 352 |
+
time_to_ack = math.ceil(time.time() - self._received_timestamp)
|
| 353 |
+
self._request_queue.put(
|
| 354 |
+
requests.AckRequest(
|
| 355 |
+
message_id=self.message_id,
|
| 356 |
+
ack_id=self._ack_id,
|
| 357 |
+
byte_size=self.size,
|
| 358 |
+
time_to_ack=time_to_ack,
|
| 359 |
+
ordering_key=self.ordering_key,
|
| 360 |
+
future=req_future,
|
| 361 |
+
opentelemetry_data=self.opentelemetry_data,
|
| 362 |
+
)
|
| 363 |
+
)
|
| 364 |
+
return future
|
| 365 |
+
|
| 366 |
+
def drop(self) -> None:
|
| 367 |
+
"""Release the message from lease management.
|
| 368 |
+
|
| 369 |
+
This informs the policy to no longer hold on to the lease for this
|
| 370 |
+
message. Pub/Sub will re-deliver the message if it is not acknowledged
|
| 371 |
+
before the existing lease expires.
|
| 372 |
+
|
| 373 |
+
.. warning::
|
| 374 |
+
For most use cases, the only reason to drop a message from
|
| 375 |
+
lease management is on `ack` or `nack`; this library
|
| 376 |
+
automatically drop()s the message on `ack` or `nack`. You probably
|
| 377 |
+
do not want to call this method directly.
|
| 378 |
+
"""
|
| 379 |
+
self._request_queue.put(
|
| 380 |
+
requests.DropRequest(
|
| 381 |
+
ack_id=self._ack_id, byte_size=self.size, ordering_key=self.ordering_key
|
| 382 |
+
)
|
| 383 |
+
)
|
| 384 |
+
|
| 385 |
+
def modify_ack_deadline(self, seconds: int) -> None:
|
| 386 |
+
"""Resets the deadline for acknowledgement.
|
| 387 |
+
|
| 388 |
+
New deadline will be the given value of seconds from now.
|
| 389 |
+
|
| 390 |
+
The default implementation handles automatically modacking received messages for you;
|
| 391 |
+
you should not need to manually deal with setting ack deadlines. The exception case is
|
| 392 |
+
if you are implementing your own custom subclass of
|
| 393 |
+
:class:`~.pubsub_v1.subcriber._consumer.Consumer`.
|
| 394 |
+
|
| 395 |
+
Args:
|
| 396 |
+
seconds (int):
|
| 397 |
+
The number of seconds to set the lease deadline to. This should be
|
| 398 |
+
between 0 and 600. Due to network latency, values below 10 are advised
|
| 399 |
+
against.
|
| 400 |
+
"""
|
| 401 |
+
self._request_queue.put(
|
| 402 |
+
requests.ModAckRequest(
|
| 403 |
+
message_id=self.message_id,
|
| 404 |
+
ack_id=self._ack_id,
|
| 405 |
+
seconds=seconds,
|
| 406 |
+
future=None,
|
| 407 |
+
opentelemetry_data=self.opentelemetry_data,
|
| 408 |
+
)
|
| 409 |
+
)
|
| 410 |
+
|
| 411 |
+
def modify_ack_deadline_with_response(self, seconds: int) -> "futures.Future":
|
| 412 |
+
"""Resets the deadline for acknowledgement and returns the response
|
| 413 |
+
status via a future.
|
| 414 |
+
|
| 415 |
+
New deadline will be the given value of seconds from now.
|
| 416 |
+
|
| 417 |
+
The default implementation handles automatically modacking received messages for you;
|
| 418 |
+
you should not need to manually deal with setting ack deadlines. The exception case is
|
| 419 |
+
if you are implementing your own custom subclass of
|
| 420 |
+
:class:`~.pubsub_v1.subcriber._consumer.Consumer`.
|
| 421 |
+
|
| 422 |
+
If exactly-once delivery is NOT enabled on the subscription, the
|
| 423 |
+
future returns immediately with an AcknowledgeStatus.SUCCESS.
|
| 424 |
+
Since modify-ack-deadline operations in Cloud Pub/Sub are best effort
|
| 425 |
+
when exactly-once delivery is disabled, the message may be re-delivered
|
| 426 |
+
within the set deadline.
|
| 427 |
+
|
| 428 |
+
If exactly-once delivery is enabled on the subscription, the
|
| 429 |
+
future returned by this method tracks the state of the
|
| 430 |
+
modify-ack-deadline operation. If the future completes successfully,
|
| 431 |
+
the message is guaranteed NOT to be re-delivered within the new deadline.
|
| 432 |
+
Otherwise, the future will contain an exception with more details about
|
| 433 |
+
the failure and the message will be redelivered according to its
|
| 434 |
+
currently-set ack deadline.
|
| 435 |
+
|
| 436 |
+
Exactly once delivery is a preview feature. For more details,
|
| 437 |
+
see https://cloud.google.com/pubsub/docs/exactly-once-delivery."
|
| 438 |
+
|
| 439 |
+
Args:
|
| 440 |
+
seconds (int):
|
| 441 |
+
The number of seconds to set the lease deadline to. This should be
|
| 442 |
+
between 0 and 600. Due to network latency, values below 10 are advised
|
| 443 |
+
against.
|
| 444 |
+
Returns:
|
| 445 |
+
futures.Future: A
|
| 446 |
+
:class:`~google.cloud.pubsub_v1.subscriber.futures.Future`
|
| 447 |
+
instance that conforms to Python Standard library's
|
| 448 |
+
:class:`~concurrent.futures.Future` interface (but not an
|
| 449 |
+
instance of that class). Call `result()` to get the result
|
| 450 |
+
of the operation; upon success, a
|
| 451 |
+
pubsub_v1.subscriber.exceptions.AcknowledgeStatus.SUCCESS
|
| 452 |
+
will be returned and upon an error, an
|
| 453 |
+
pubsub_v1.subscriber.exceptions.AcknowledgeError exception
|
| 454 |
+
will be thrown.
|
| 455 |
+
|
| 456 |
+
"""
|
| 457 |
+
req_future: Optional[futures.Future]
|
| 458 |
+
if self._exactly_once_delivery_enabled_func():
|
| 459 |
+
future = futures.Future()
|
| 460 |
+
req_future = future
|
| 461 |
+
else:
|
| 462 |
+
future = _SUCCESS_FUTURE
|
| 463 |
+
req_future = None
|
| 464 |
+
|
| 465 |
+
self._request_queue.put(
|
| 466 |
+
requests.ModAckRequest(
|
| 467 |
+
message_id=self.message_id,
|
| 468 |
+
ack_id=self._ack_id,
|
| 469 |
+
seconds=seconds,
|
| 470 |
+
future=req_future,
|
| 471 |
+
opentelemetry_data=self.opentelemetry_data,
|
| 472 |
+
)
|
| 473 |
+
)
|
| 474 |
+
|
| 475 |
+
return future
|
| 476 |
+
|
| 477 |
+
def nack(self) -> None:
|
| 478 |
+
"""Decline to acknowledge the given message.
|
| 479 |
+
|
| 480 |
+
This will cause the message to be re-delivered to subscribers. Re-deliveries
|
| 481 |
+
may take place immediately or after a delay, and may arrive at this subscriber
|
| 482 |
+
or another.
|
| 483 |
+
"""
|
| 484 |
+
_ACK_NACK_LOGGER.debug(
|
| 485 |
+
"Called nack for message (id=%s, ack_id=%s, ordering_key=%s, exactly_once=%s)",
|
| 486 |
+
self.message_id,
|
| 487 |
+
self.ack_id,
|
| 488 |
+
self.ordering_key,
|
| 489 |
+
self._exactly_once_delivery_enabled_func(),
|
| 490 |
+
)
|
| 491 |
+
if self.opentelemetry_data:
|
| 492 |
+
self.opentelemetry_data.add_process_span_event("nack called")
|
| 493 |
+
self.opentelemetry_data.end_process_span()
|
| 494 |
+
self._request_queue.put(
|
| 495 |
+
requests.NackRequest(
|
| 496 |
+
ack_id=self._ack_id,
|
| 497 |
+
byte_size=self.size,
|
| 498 |
+
ordering_key=self.ordering_key,
|
| 499 |
+
future=None,
|
| 500 |
+
opentelemetry_data=self.opentelemetry_data,
|
| 501 |
+
)
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
def nack_with_response(self) -> "futures.Future":
|
| 505 |
+
"""Decline to acknowledge the given message, returning the response status via
|
| 506 |
+
a future.
|
| 507 |
+
|
| 508 |
+
This will cause the message to be re-delivered to subscribers. Re-deliveries
|
| 509 |
+
may take place immediately or after a delay, and may arrive at this subscriber
|
| 510 |
+
or another.
|
| 511 |
+
|
| 512 |
+
If exactly-once delivery is NOT enabled on the subscription, the
|
| 513 |
+
future returns immediately with an AcknowledgeStatus.SUCCESS.
|
| 514 |
+
|
| 515 |
+
If exactly-once delivery is enabled on the subscription, the
|
| 516 |
+
future returned by this method tracks the state of the
|
| 517 |
+
nack operation. If the future completes successfully,
|
| 518 |
+
the future's result will be an AcknowledgeStatus.SUCCESS.
|
| 519 |
+
Otherwise, the future will contain an exception with more details about
|
| 520 |
+
the failure.
|
| 521 |
+
|
| 522 |
+
Exactly once delivery is a preview feature. For more details,
|
| 523 |
+
see https://cloud.google.com/pubsub/docs/exactly-once-delivery."
|
| 524 |
+
|
| 525 |
+
Returns:
|
| 526 |
+
futures.Future: A
|
| 527 |
+
:class:`~google.cloud.pubsub_v1.subscriber.futures.Future`
|
| 528 |
+
instance that conforms to Python Standard library's
|
| 529 |
+
:class:`~concurrent.futures.Future` interface (but not an
|
| 530 |
+
instance of that class). Call `result()` to get the result
|
| 531 |
+
of the operation; upon success, a
|
| 532 |
+
pubsub_v1.subscriber.exceptions.AcknowledgeStatus.SUCCESS
|
| 533 |
+
will be returned and upon an error, an
|
| 534 |
+
pubsub_v1.subscriber.exceptions.AcknowledgeError exception
|
| 535 |
+
will be thrown.
|
| 536 |
+
|
| 537 |
+
"""
|
| 538 |
+
if self.opentelemetry_data:
|
| 539 |
+
self.opentelemetry_data.add_process_span_event("nack called")
|
| 540 |
+
self.opentelemetry_data.end_process_span()
|
| 541 |
+
req_future: Optional[futures.Future]
|
| 542 |
+
if self._exactly_once_delivery_enabled_func():
|
| 543 |
+
future = futures.Future()
|
| 544 |
+
req_future = future
|
| 545 |
+
else:
|
| 546 |
+
future = _SUCCESS_FUTURE
|
| 547 |
+
req_future = None
|
| 548 |
+
|
| 549 |
+
self._request_queue.put(
|
| 550 |
+
requests.NackRequest(
|
| 551 |
+
ack_id=self._ack_id,
|
| 552 |
+
byte_size=self.size,
|
| 553 |
+
ordering_key=self.ordering_key,
|
| 554 |
+
future=req_future,
|
| 555 |
+
opentelemetry_data=self.opentelemetry_data,
|
| 556 |
+
)
|
| 557 |
+
)
|
| 558 |
+
|
| 559 |
+
return future
|
| 560 |
+
|
| 561 |
+
@property
|
| 562 |
+
def exactly_once_enabled(self):
|
| 563 |
+
return self._exactly_once_delivery_enabled_func()
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/subscriber/scheduler.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Schedulers provide means to *schedule* callbacks asynchronously.
|
| 16 |
+
|
| 17 |
+
These are used by the subscriber to call the user-provided callback to process
|
| 18 |
+
each message.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import abc
|
| 22 |
+
import concurrent.futures
|
| 23 |
+
import queue
|
| 24 |
+
import sys
|
| 25 |
+
import typing
|
| 26 |
+
import warnings
|
| 27 |
+
from typing import Callable, List, Optional
|
| 28 |
+
|
| 29 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 30 |
+
from google.cloud import pubsub_v1
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class Scheduler(metaclass=abc.ABCMeta):
|
| 34 |
+
"""Abstract base class for schedulers.
|
| 35 |
+
|
| 36 |
+
Schedulers are used to schedule callbacks asynchronously.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
@property
|
| 40 |
+
@abc.abstractmethod
|
| 41 |
+
def queue(self) -> "queue.Queue": # pragma: NO COVER
|
| 42 |
+
"""Queue: A concurrency-safe queue specific to the underlying
|
| 43 |
+
concurrency implementation.
|
| 44 |
+
|
| 45 |
+
This queue is used to send messages *back* to the scheduling actor.
|
| 46 |
+
"""
|
| 47 |
+
raise NotImplementedError
|
| 48 |
+
|
| 49 |
+
@abc.abstractmethod
|
| 50 |
+
def schedule(self, callback: Callable, *args, **kwargs) -> None: # pragma: NO COVER
|
| 51 |
+
"""Schedule the callback to be called asynchronously.
|
| 52 |
+
|
| 53 |
+
Args:
|
| 54 |
+
callback: The function to call.
|
| 55 |
+
args: Positional arguments passed to the callback.
|
| 56 |
+
kwargs: Key-word arguments passed to the callback.
|
| 57 |
+
|
| 58 |
+
Returns:
|
| 59 |
+
None
|
| 60 |
+
"""
|
| 61 |
+
raise NotImplementedError
|
| 62 |
+
|
| 63 |
+
@abc.abstractmethod
|
| 64 |
+
def shutdown(
|
| 65 |
+
self, await_msg_callbacks: bool = False
|
| 66 |
+
) -> List["pubsub_v1.subscriber.message.Message"]: # pragma: NO COVER
|
| 67 |
+
"""Shuts down the scheduler and immediately end all pending callbacks.
|
| 68 |
+
|
| 69 |
+
Args:
|
| 70 |
+
await_msg_callbacks:
|
| 71 |
+
If ``True``, the method will block until all currently executing
|
| 72 |
+
callbacks are done processing. If ``False`` (default), the
|
| 73 |
+
method will not wait for the currently running callbacks to complete.
|
| 74 |
+
|
| 75 |
+
Returns:
|
| 76 |
+
The messages submitted to the scheduler that were not yet dispatched
|
| 77 |
+
to their callbacks.
|
| 78 |
+
It is assumed that each message was submitted to the scheduler as the
|
| 79 |
+
first positional argument to the provided callback.
|
| 80 |
+
"""
|
| 81 |
+
raise NotImplementedError
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _make_default_thread_pool_executor() -> concurrent.futures.ThreadPoolExecutor:
|
| 85 |
+
return concurrent.futures.ThreadPoolExecutor(
|
| 86 |
+
max_workers=10, thread_name_prefix="ThreadPoolExecutor-ThreadScheduler"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class ThreadScheduler(Scheduler):
|
| 91 |
+
"""A thread pool-based scheduler. It must not be shared across
|
| 92 |
+
SubscriberClients.
|
| 93 |
+
|
| 94 |
+
This scheduler is useful in typical I/O-bound message processing.
|
| 95 |
+
|
| 96 |
+
Args:
|
| 97 |
+
executor:
|
| 98 |
+
An optional executor to use. If not specified, a default one
|
| 99 |
+
will be created.
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
def __init__(
|
| 103 |
+
self, executor: Optional[concurrent.futures.ThreadPoolExecutor] = None
|
| 104 |
+
):
|
| 105 |
+
self._queue: queue.Queue = queue.Queue()
|
| 106 |
+
if executor is None:
|
| 107 |
+
self._executor = _make_default_thread_pool_executor()
|
| 108 |
+
else:
|
| 109 |
+
self._executor = executor
|
| 110 |
+
|
| 111 |
+
@property
|
| 112 |
+
def queue(self):
|
| 113 |
+
"""Queue: A thread-safe queue used for communication between callbacks
|
| 114 |
+
and the scheduling thread."""
|
| 115 |
+
return self._queue
|
| 116 |
+
|
| 117 |
+
def schedule(self, callback: Callable, *args, **kwargs) -> None:
|
| 118 |
+
"""Schedule the callback to be called asynchronously in a thread pool.
|
| 119 |
+
|
| 120 |
+
Args:
|
| 121 |
+
callback: The function to call.
|
| 122 |
+
args: Positional arguments passed to the callback.
|
| 123 |
+
kwargs: Key-word arguments passed to the callback.
|
| 124 |
+
|
| 125 |
+
Returns:
|
| 126 |
+
None
|
| 127 |
+
"""
|
| 128 |
+
try:
|
| 129 |
+
self._executor.submit(callback, *args, **kwargs)
|
| 130 |
+
except RuntimeError:
|
| 131 |
+
warnings.warn(
|
| 132 |
+
"Scheduling a callback after executor shutdown.",
|
| 133 |
+
category=RuntimeWarning,
|
| 134 |
+
stacklevel=2,
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
def shutdown(
|
| 138 |
+
self, await_msg_callbacks: bool = False
|
| 139 |
+
) -> List["pubsub_v1.subscriber.message.Message"]:
|
| 140 |
+
"""Shut down the scheduler and immediately end all pending callbacks.
|
| 141 |
+
|
| 142 |
+
Args:
|
| 143 |
+
await_msg_callbacks:
|
| 144 |
+
If ``True``, the method will block until all currently executing
|
| 145 |
+
executor threads are done processing. If ``False`` (default), the
|
| 146 |
+
method will not wait for the currently running threads to complete.
|
| 147 |
+
|
| 148 |
+
Returns:
|
| 149 |
+
The messages submitted to the scheduler that were not yet dispatched
|
| 150 |
+
to their callbacks.
|
| 151 |
+
It is assumed that each message was submitted to the scheduler as the
|
| 152 |
+
first positional argument to the provided callback.
|
| 153 |
+
"""
|
| 154 |
+
dropped_messages = []
|
| 155 |
+
|
| 156 |
+
# Drop all pending item from the executor. Without this, the executor will also
|
| 157 |
+
# try to process any pending work items before termination, which is undesirable.
|
| 158 |
+
#
|
| 159 |
+
# TODO: Replace the logic below by passing `cancel_futures=True` to shutdown()
|
| 160 |
+
# once we only need to support Python 3.9+.
|
| 161 |
+
try:
|
| 162 |
+
while True:
|
| 163 |
+
work_item = self._executor._work_queue.get(block=False)
|
| 164 |
+
if work_item is None: # Exceutor in shutdown mode.
|
| 165 |
+
continue
|
| 166 |
+
|
| 167 |
+
dropped_message = None
|
| 168 |
+
if sys.version_info < (3, 14):
|
| 169 |
+
# For Python < 3.14, work_item.args is a tuple of positional arguments.
|
| 170 |
+
# The message is expected to be the first argument.
|
| 171 |
+
if hasattr(work_item, "args") and work_item.args:
|
| 172 |
+
dropped_message = work_item.args[0] # type: ignore[index]
|
| 173 |
+
else:
|
| 174 |
+
# For Python >= 3.14, work_item.task is (fn, args, kwargs).
|
| 175 |
+
# The message is expected to be the first item in the args tuple (task[1]).
|
| 176 |
+
if (
|
| 177 |
+
hasattr(work_item, "task")
|
| 178 |
+
and len(work_item.task) == 3
|
| 179 |
+
and work_item.task[1]
|
| 180 |
+
):
|
| 181 |
+
dropped_message = work_item.task[1][0]
|
| 182 |
+
|
| 183 |
+
if dropped_message is not None:
|
| 184 |
+
dropped_messages.append(dropped_message)
|
| 185 |
+
except queue.Empty:
|
| 186 |
+
pass
|
| 187 |
+
|
| 188 |
+
self._executor.shutdown(wait=await_msg_callbacks)
|
| 189 |
+
return dropped_messages
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/pubsub_v1/types.py
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from __future__ import absolute_import
|
| 16 |
+
|
| 17 |
+
import collections
|
| 18 |
+
import enum
|
| 19 |
+
import inspect
|
| 20 |
+
import sys
|
| 21 |
+
import typing
|
| 22 |
+
from typing import Dict, NamedTuple, Union
|
| 23 |
+
|
| 24 |
+
import proto # type: ignore
|
| 25 |
+
from google.api import http_pb2 # type: ignore
|
| 26 |
+
from google.api_core import gapic_v1
|
| 27 |
+
from google.api_core.protobuf_helpers import get_messages
|
| 28 |
+
from google.api_core.timeout import ConstantTimeout
|
| 29 |
+
from google.iam.v1 import (
|
| 30 |
+
iam_policy_pb2, # type: ignore
|
| 31 |
+
policy_pb2,
|
| 32 |
+
)
|
| 33 |
+
from google.iam.v1.logging import audit_data_pb2 # type: ignore
|
| 34 |
+
from google.protobuf import (
|
| 35 |
+
descriptor_pb2,
|
| 36 |
+
duration_pb2,
|
| 37 |
+
empty_pb2,
|
| 38 |
+
field_mask_pb2,
|
| 39 |
+
timestamp_pb2,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
from google.pubsub_v1.types import pubsub as pubsub_gapic_types
|
| 43 |
+
|
| 44 |
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
| 45 |
+
from types import ModuleType
|
| 46 |
+
|
| 47 |
+
from google.pubsub_v1 import types as gapic_types
|
| 48 |
+
from google.pubsub_v1.services.publisher.client import OptionalRetry
|
| 49 |
+
|
| 50 |
+
# TODO: Eventually implement OptionalTimeout in the GAPIC code generator and import
|
| 51 |
+
# it from the generated code. It's the same solution that is used for OptionalRetry.
|
| 52 |
+
# https://github.com/googleapis/gapic-generator-python/pull/1032/files
|
| 53 |
+
# https://github.com/googleapis/gapic-generator-python/pull/1065/files
|
| 54 |
+
if hasattr(gapic_v1.method, "_MethodDefault"):
|
| 55 |
+
# _MethodDefault was only added in google-api-core==2.2.2
|
| 56 |
+
OptionalTimeout = Union[gapic_types.TimeoutType, gapic_v1.method._MethodDefault]
|
| 57 |
+
else:
|
| 58 |
+
OptionalTimeout = Union[gapic_types.TimeoutType, object] # type: ignore
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# Define the default values for batching.
|
| 62 |
+
#
|
| 63 |
+
# This class is used when creating a publisher or subscriber client, and
|
| 64 |
+
# these settings can be altered to tweak Pub/Sub behavior.
|
| 65 |
+
# The defaults should be fine for most use cases.
|
| 66 |
+
class BatchSettings(NamedTuple):
|
| 67 |
+
"""The settings for batch publishing the messages.
|
| 68 |
+
|
| 69 |
+
Attributes:
|
| 70 |
+
max_bytes (int):
|
| 71 |
+
The maximum total size of the messages to collect before automatically
|
| 72 |
+
publishing the batch, including any byte size overhead of the publish
|
| 73 |
+
request itself. The maximum value is bound by the server-side limit of
|
| 74 |
+
10_000_000 bytes. Defaults to 1 MB.
|
| 75 |
+
max_latency (float):
|
| 76 |
+
The maximum number of seconds to wait for additional messages before
|
| 77 |
+
automatically publishing the batch. Defaults to 10ms.
|
| 78 |
+
max_messages (int):
|
| 79 |
+
The maximum number of messages to collect before automatically
|
| 80 |
+
publishing the batch. Defaults to 100.
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
max_bytes: int = 1 * 1000 * 1000 # 1 MB
|
| 84 |
+
(
|
| 85 |
+
"The maximum total size of the messages to collect before automatically "
|
| 86 |
+
"publishing the batch, including any byte size overhead of the publish "
|
| 87 |
+
"request itself. The maximum value is bound by the server-side limit of "
|
| 88 |
+
"10_000_000 bytes."
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
max_latency: float = 0.01 # 10 ms
|
| 92 |
+
(
|
| 93 |
+
"The maximum number of seconds to wait for additional messages before "
|
| 94 |
+
"automatically publishing the batch."
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
max_messages: int = 100
|
| 98 |
+
(
|
| 99 |
+
"The maximum number of messages to collect before automatically "
|
| 100 |
+
"publishing the batch."
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class LimitExceededBehavior(str, enum.Enum):
|
| 105 |
+
"""The possible actions when exceeding the publish flow control limits."""
|
| 106 |
+
|
| 107 |
+
IGNORE = "ignore"
|
| 108 |
+
BLOCK = "block"
|
| 109 |
+
ERROR = "error"
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class PublishFlowControl(NamedTuple):
|
| 113 |
+
"""The client flow control settings for message publishing.
|
| 114 |
+
|
| 115 |
+
Attributes:
|
| 116 |
+
message_limit (int):
|
| 117 |
+
The maximum number of messages awaiting to be published.
|
| 118 |
+
Defaults to 1000.
|
| 119 |
+
byte_limit (int):
|
| 120 |
+
The maximum total size of messages awaiting to be published.
|
| 121 |
+
Defaults to 10MB.
|
| 122 |
+
limit_exceeded_behavior (LimitExceededBehavior):
|
| 123 |
+
The action to take when publish flow control limits are exceeded.
|
| 124 |
+
Defaults to LimitExceededBehavior.IGNORE.
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
message_limit: int = 10 * BatchSettings.__new__.__defaults__[2] # type: ignore
|
| 128 |
+
"""The maximum number of messages awaiting to be published."""
|
| 129 |
+
|
| 130 |
+
byte_limit: int = 10 * BatchSettings.__new__.__defaults__[0] # type: ignore
|
| 131 |
+
"""The maximum total size of messages awaiting to be published."""
|
| 132 |
+
|
| 133 |
+
limit_exceeded_behavior: LimitExceededBehavior = LimitExceededBehavior.IGNORE
|
| 134 |
+
"""The action to take when publish flow control limits are exceeded."""
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
# Define the default subscriber options.
|
| 138 |
+
#
|
| 139 |
+
# This class is used when creating a subscriber client to pass in options
|
| 140 |
+
# to enable/disable features.
|
| 141 |
+
class SubscriberOptions(NamedTuple):
|
| 142 |
+
"""
|
| 143 |
+
Options for the subscriber client.
|
| 144 |
+
Attributes:
|
| 145 |
+
enable_open_telemetry_tracing (bool):
|
| 146 |
+
Whether to enable OpenTelemetry tracing. Defaults to False.
|
| 147 |
+
"""
|
| 148 |
+
|
| 149 |
+
enable_open_telemetry_tracing: bool = False
|
| 150 |
+
"""
|
| 151 |
+
Whether to enable OpenTelemetry tracing.
|
| 152 |
+
|
| 153 |
+
Warning: traces are subject to change. The name and attributes of a span might
|
| 154 |
+
change without notice. Only use run traces interactively. Don't use in
|
| 155 |
+
automation. Running non-interactive traces can cause problems if the underlying
|
| 156 |
+
trace architecture changes without notice.
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
# Define the default publisher options.
|
| 161 |
+
#
|
| 162 |
+
# This class is used when creating a publisher client to pass in options
|
| 163 |
+
# to enable/disable features.
|
| 164 |
+
class PublisherOptions(NamedTuple):
|
| 165 |
+
"""The options for the publisher client.
|
| 166 |
+
|
| 167 |
+
Attributes:
|
| 168 |
+
enable_message_ordering (bool):
|
| 169 |
+
Whether to order messages in a batch by a supplied ordering key.
|
| 170 |
+
Defaults to false.
|
| 171 |
+
flow_control (PublishFlowControl):
|
| 172 |
+
Flow control settings for message publishing by the client. By default
|
| 173 |
+
the publisher client does not do any throttling.
|
| 174 |
+
retry (OptionalRetry):
|
| 175 |
+
Retry settings for message publishing by the client. This should be
|
| 176 |
+
an instance of :class:`google.api_core.retry.Retry`.
|
| 177 |
+
timeout (OptionalTimeout):
|
| 178 |
+
Timeout settings for message publishing by the client. It should be
|
| 179 |
+
compatible with :class:`~.pubsub_v1.types.TimeoutType`.
|
| 180 |
+
"""
|
| 181 |
+
|
| 182 |
+
enable_message_ordering: bool = False
|
| 183 |
+
"""Whether to order messages in a batch by a supplied ordering key."""
|
| 184 |
+
|
| 185 |
+
flow_control: PublishFlowControl = PublishFlowControl()
|
| 186 |
+
(
|
| 187 |
+
"Flow control settings for message publishing by the client. By default "
|
| 188 |
+
"the publisher client does not do any throttling."
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
retry: "OptionalRetry" = gapic_v1.method.DEFAULT # use api_core default
|
| 192 |
+
(
|
| 193 |
+
"Retry settings for message publishing by the client. This should be "
|
| 194 |
+
"an instance of :class:`google.api_core.retry.Retry`."
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
# Use ConstantTimeout instead of api_core default because the default
|
| 198 |
+
# value results in retries with zero deadline.
|
| 199 |
+
# Refer https://github.com/googleapis/python-api-core/issues/654
|
| 200 |
+
timeout: "OptionalTimeout" = ConstantTimeout(60)
|
| 201 |
+
(
|
| 202 |
+
"Timeout settings for message publishing by the client. It should be "
|
| 203 |
+
"compatible with :class:`~.pubsub_v1.types.TimeoutType`."
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
enable_open_telemetry_tracing: bool = False # disabled by default
|
| 207 |
+
"""
|
| 208 |
+
Open Telemetry tracing is enabled if this is set to True.
|
| 209 |
+
|
| 210 |
+
Warning: traces are subject to change. The name and attributes of a span might
|
| 211 |
+
change without notice. Only use run traces interactively. Don't use in
|
| 212 |
+
automation. Running non-interactive traces can cause problems if the underlying
|
| 213 |
+
trace architecture changes without notice.
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
# Define the type class and default values for flow control settings.
|
| 218 |
+
#
|
| 219 |
+
# This class is used when creating a publisher or subscriber client, and
|
| 220 |
+
# these settings can be altered to tweak Pub/Sub behavior.
|
| 221 |
+
# The defaults should be fine for most use cases.
|
| 222 |
+
class FlowControl(NamedTuple):
|
| 223 |
+
"""The settings for controlling the rate at which messages are pulled
|
| 224 |
+
with an asynchronous subscription.
|
| 225 |
+
|
| 226 |
+
Attributes:
|
| 227 |
+
max_bytes (int):
|
| 228 |
+
The maximum total size of received - but not yet processed - messages
|
| 229 |
+
before pausing the message stream. Defaults to 100 MiB.
|
| 230 |
+
max_messages (int):
|
| 231 |
+
The maximum number of received - but not yet processed - messages before
|
| 232 |
+
pausing the message stream. Defaults to 1000.
|
| 233 |
+
max_lease_duration (float):
|
| 234 |
+
The maximum amount of time in seconds to hold a lease on a message
|
| 235 |
+
before dropping it from the lease management. Defaults to 1 hour.
|
| 236 |
+
min_duration_per_lease_extension (float):
|
| 237 |
+
The min amount of time in seconds for a single lease extension attempt.
|
| 238 |
+
Must be between 10 and 600 (inclusive). Ignored by default, but set to
|
| 239 |
+
60 seconds if the subscription has exactly-once delivery enabled.
|
| 240 |
+
max_duration_per_lease_extension (float):
|
| 241 |
+
The max amount of time in seconds for a single lease extension attempt.
|
| 242 |
+
Bounds the delay before a message redelivery if the subscriber
|
| 243 |
+
fails to extend the deadline. Must be between 10 and 600 (inclusive). Ignored
|
| 244 |
+
if set to 0.
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
max_bytes: int = 100 * 1024 * 1024 # 100 MiB
|
| 248 |
+
(
|
| 249 |
+
"The maximum total size of received - but not yet processed - messages "
|
| 250 |
+
"before pausing the message stream."
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
max_messages: int = 1000
|
| 254 |
+
(
|
| 255 |
+
"The maximum number of received - but not yet processed - messages before "
|
| 256 |
+
"pausing the message stream."
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
max_lease_duration: float = 1 * 60 * 60 # 1 hour
|
| 260 |
+
(
|
| 261 |
+
"The maximum amount of time in seconds to hold a lease on a message "
|
| 262 |
+
"before dropping it from the lease management."
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
min_duration_per_lease_extension: float = 0
|
| 266 |
+
(
|
| 267 |
+
"The min amount of time in seconds for a single lease extension attempt. "
|
| 268 |
+
"Must be between 10 and 600 (inclusive). Ignored by default, but set to "
|
| 269 |
+
"60 seconds if the subscription has exactly-once delivery enabled."
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
max_duration_per_lease_extension: float = 0 # disabled by default
|
| 273 |
+
(
|
| 274 |
+
"The max amount of time in seconds for a single lease extension attempt. "
|
| 275 |
+
"Bounds the delay before a message redelivery if the subscriber "
|
| 276 |
+
"fails to extend the deadline. Must be between 10 and 600 (inclusive). Ignored "
|
| 277 |
+
"if set to 0."
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
# The current api core helper does not find new proto messages of type proto.Message,
|
| 282 |
+
# thus we need our own helper. Adjusted from
|
| 283 |
+
# https://github.com/googleapis/python-api-core/blob/8595f620e7d8295b6a379d6fd7979af3bef717e2/google/api_core/protobuf_helpers.py#L101-L118
|
| 284 |
+
def _get_protobuf_messages(module: "ModuleType") -> Dict[str, proto.Message]:
|
| 285 |
+
"""Discover all protobuf Message classes in a given import module.
|
| 286 |
+
|
| 287 |
+
Args:
|
| 288 |
+
module (module): A Python module; :func:`dir` will be run against this
|
| 289 |
+
module to find Message subclasses.
|
| 290 |
+
|
| 291 |
+
Returns:
|
| 292 |
+
dict[str, proto.Message]: A dictionary with the
|
| 293 |
+
Message class names as keys, and the Message subclasses themselves
|
| 294 |
+
as values.
|
| 295 |
+
"""
|
| 296 |
+
answer = collections.OrderedDict()
|
| 297 |
+
for name in dir(module):
|
| 298 |
+
candidate = getattr(module, name)
|
| 299 |
+
if inspect.isclass(candidate) and issubclass(candidate, proto.Message):
|
| 300 |
+
answer[name] = candidate
|
| 301 |
+
return answer
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
_shared_modules = [
|
| 305 |
+
http_pb2,
|
| 306 |
+
iam_policy_pb2,
|
| 307 |
+
policy_pb2,
|
| 308 |
+
audit_data_pb2,
|
| 309 |
+
descriptor_pb2,
|
| 310 |
+
duration_pb2,
|
| 311 |
+
empty_pb2,
|
| 312 |
+
field_mask_pb2,
|
| 313 |
+
timestamp_pb2,
|
| 314 |
+
]
|
| 315 |
+
|
| 316 |
+
_local_modules = [pubsub_gapic_types]
|
| 317 |
+
|
| 318 |
+
names = [
|
| 319 |
+
"BatchSettings",
|
| 320 |
+
"LimitExceededBehavior",
|
| 321 |
+
"PublishFlowControl",
|
| 322 |
+
"PublisherOptions",
|
| 323 |
+
"FlowControl",
|
| 324 |
+
]
|
| 325 |
+
|
| 326 |
+
for module in _shared_modules:
|
| 327 |
+
for name, message in get_messages(module).items():
|
| 328 |
+
setattr(sys.modules[__name__], name, message)
|
| 329 |
+
names.append(name)
|
| 330 |
+
|
| 331 |
+
for module in _local_modules:
|
| 332 |
+
for name, message in _get_protobuf_messages(module).items():
|
| 333 |
+
message.__module__ = "google.cloud.pubsub_v1.types"
|
| 334 |
+
setattr(sys.modules[__name__], name, message)
|
| 335 |
+
names.append(name)
|
| 336 |
+
|
| 337 |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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
from google.cloud.resourcemanager import gapic_version as package_version
|
| 17 |
+
|
| 18 |
+
__version__ = package_version.__version__
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
from google.cloud.resourcemanager_v3.services.folders.async_client import (
|
| 22 |
+
FoldersAsyncClient,
|
| 23 |
+
)
|
| 24 |
+
from google.cloud.resourcemanager_v3.services.folders.client import FoldersClient
|
| 25 |
+
from google.cloud.resourcemanager_v3.services.organizations.async_client import (
|
| 26 |
+
OrganizationsAsyncClient,
|
| 27 |
+
)
|
| 28 |
+
from google.cloud.resourcemanager_v3.services.organizations.client import (
|
| 29 |
+
OrganizationsClient,
|
| 30 |
+
)
|
| 31 |
+
from google.cloud.resourcemanager_v3.services.projects.async_client import (
|
| 32 |
+
ProjectsAsyncClient,
|
| 33 |
+
)
|
| 34 |
+
from google.cloud.resourcemanager_v3.services.projects.client import ProjectsClient
|
| 35 |
+
from google.cloud.resourcemanager_v3.services.tag_bindings.async_client import (
|
| 36 |
+
TagBindingsAsyncClient,
|
| 37 |
+
)
|
| 38 |
+
from google.cloud.resourcemanager_v3.services.tag_bindings.client import (
|
| 39 |
+
TagBindingsClient,
|
| 40 |
+
)
|
| 41 |
+
from google.cloud.resourcemanager_v3.services.tag_holds.async_client import (
|
| 42 |
+
TagHoldsAsyncClient,
|
| 43 |
+
)
|
| 44 |
+
from google.cloud.resourcemanager_v3.services.tag_holds.client import TagHoldsClient
|
| 45 |
+
from google.cloud.resourcemanager_v3.services.tag_keys.async_client import (
|
| 46 |
+
TagKeysAsyncClient,
|
| 47 |
+
)
|
| 48 |
+
from google.cloud.resourcemanager_v3.services.tag_keys.client import TagKeysClient
|
| 49 |
+
from google.cloud.resourcemanager_v3.services.tag_values.async_client import (
|
| 50 |
+
TagValuesAsyncClient,
|
| 51 |
+
)
|
| 52 |
+
from google.cloud.resourcemanager_v3.services.tag_values.client import TagValuesClient
|
| 53 |
+
from google.cloud.resourcemanager_v3.types.folders import (
|
| 54 |
+
CreateFolderMetadata,
|
| 55 |
+
CreateFolderRequest,
|
| 56 |
+
DeleteFolderMetadata,
|
| 57 |
+
DeleteFolderRequest,
|
| 58 |
+
Folder,
|
| 59 |
+
GetFolderRequest,
|
| 60 |
+
ListFoldersRequest,
|
| 61 |
+
ListFoldersResponse,
|
| 62 |
+
MoveFolderMetadata,
|
| 63 |
+
MoveFolderRequest,
|
| 64 |
+
SearchFoldersRequest,
|
| 65 |
+
SearchFoldersResponse,
|
| 66 |
+
UndeleteFolderMetadata,
|
| 67 |
+
UndeleteFolderRequest,
|
| 68 |
+
UpdateFolderMetadata,
|
| 69 |
+
UpdateFolderRequest,
|
| 70 |
+
)
|
| 71 |
+
from google.cloud.resourcemanager_v3.types.organizations import (
|
| 72 |
+
DeleteOrganizationMetadata,
|
| 73 |
+
GetOrganizationRequest,
|
| 74 |
+
Organization,
|
| 75 |
+
SearchOrganizationsRequest,
|
| 76 |
+
SearchOrganizationsResponse,
|
| 77 |
+
UndeleteOrganizationMetadata,
|
| 78 |
+
)
|
| 79 |
+
from google.cloud.resourcemanager_v3.types.projects import (
|
| 80 |
+
CreateProjectMetadata,
|
| 81 |
+
CreateProjectRequest,
|
| 82 |
+
DeleteProjectMetadata,
|
| 83 |
+
DeleteProjectRequest,
|
| 84 |
+
GetProjectRequest,
|
| 85 |
+
ListProjectsRequest,
|
| 86 |
+
ListProjectsResponse,
|
| 87 |
+
MoveProjectMetadata,
|
| 88 |
+
MoveProjectRequest,
|
| 89 |
+
Project,
|
| 90 |
+
SearchProjectsRequest,
|
| 91 |
+
SearchProjectsResponse,
|
| 92 |
+
UndeleteProjectMetadata,
|
| 93 |
+
UndeleteProjectRequest,
|
| 94 |
+
UpdateProjectMetadata,
|
| 95 |
+
UpdateProjectRequest,
|
| 96 |
+
)
|
| 97 |
+
from google.cloud.resourcemanager_v3.types.tag_bindings import (
|
| 98 |
+
CreateTagBindingMetadata,
|
| 99 |
+
CreateTagBindingRequest,
|
| 100 |
+
DeleteTagBindingMetadata,
|
| 101 |
+
DeleteTagBindingRequest,
|
| 102 |
+
EffectiveTag,
|
| 103 |
+
ListEffectiveTagsRequest,
|
| 104 |
+
ListEffectiveTagsResponse,
|
| 105 |
+
ListTagBindingsRequest,
|
| 106 |
+
ListTagBindingsResponse,
|
| 107 |
+
TagBinding,
|
| 108 |
+
)
|
| 109 |
+
from google.cloud.resourcemanager_v3.types.tag_holds import (
|
| 110 |
+
CreateTagHoldMetadata,
|
| 111 |
+
CreateTagHoldRequest,
|
| 112 |
+
DeleteTagHoldMetadata,
|
| 113 |
+
DeleteTagHoldRequest,
|
| 114 |
+
ListTagHoldsRequest,
|
| 115 |
+
ListTagHoldsResponse,
|
| 116 |
+
TagHold,
|
| 117 |
+
)
|
| 118 |
+
from google.cloud.resourcemanager_v3.types.tag_keys import (
|
| 119 |
+
CreateTagKeyMetadata,
|
| 120 |
+
CreateTagKeyRequest,
|
| 121 |
+
DeleteTagKeyMetadata,
|
| 122 |
+
DeleteTagKeyRequest,
|
| 123 |
+
GetNamespacedTagKeyRequest,
|
| 124 |
+
GetTagKeyRequest,
|
| 125 |
+
ListTagKeysRequest,
|
| 126 |
+
ListTagKeysResponse,
|
| 127 |
+
Purpose,
|
| 128 |
+
TagKey,
|
| 129 |
+
UpdateTagKeyMetadata,
|
| 130 |
+
UpdateTagKeyRequest,
|
| 131 |
+
)
|
| 132 |
+
from google.cloud.resourcemanager_v3.types.tag_values import (
|
| 133 |
+
CreateTagValueMetadata,
|
| 134 |
+
CreateTagValueRequest,
|
| 135 |
+
DeleteTagValueMetadata,
|
| 136 |
+
DeleteTagValueRequest,
|
| 137 |
+
GetNamespacedTagValueRequest,
|
| 138 |
+
GetTagValueRequest,
|
| 139 |
+
ListTagValuesRequest,
|
| 140 |
+
ListTagValuesResponse,
|
| 141 |
+
TagValue,
|
| 142 |
+
UpdateTagValueMetadata,
|
| 143 |
+
UpdateTagValueRequest,
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
__all__ = (
|
| 147 |
+
"FoldersClient",
|
| 148 |
+
"FoldersAsyncClient",
|
| 149 |
+
"OrganizationsClient",
|
| 150 |
+
"OrganizationsAsyncClient",
|
| 151 |
+
"ProjectsClient",
|
| 152 |
+
"ProjectsAsyncClient",
|
| 153 |
+
"TagBindingsClient",
|
| 154 |
+
"TagBindingsAsyncClient",
|
| 155 |
+
"TagHoldsClient",
|
| 156 |
+
"TagHoldsAsyncClient",
|
| 157 |
+
"TagKeysClient",
|
| 158 |
+
"TagKeysAsyncClient",
|
| 159 |
+
"TagValuesClient",
|
| 160 |
+
"TagValuesAsyncClient",
|
| 161 |
+
"CreateFolderMetadata",
|
| 162 |
+
"CreateFolderRequest",
|
| 163 |
+
"DeleteFolderMetadata",
|
| 164 |
+
"DeleteFolderRequest",
|
| 165 |
+
"Folder",
|
| 166 |
+
"GetFolderRequest",
|
| 167 |
+
"ListFoldersRequest",
|
| 168 |
+
"ListFoldersResponse",
|
| 169 |
+
"MoveFolderMetadata",
|
| 170 |
+
"MoveFolderRequest",
|
| 171 |
+
"SearchFoldersRequest",
|
| 172 |
+
"SearchFoldersResponse",
|
| 173 |
+
"UndeleteFolderMetadata",
|
| 174 |
+
"UndeleteFolderRequest",
|
| 175 |
+
"UpdateFolderMetadata",
|
| 176 |
+
"UpdateFolderRequest",
|
| 177 |
+
"DeleteOrganizationMetadata",
|
| 178 |
+
"GetOrganizationRequest",
|
| 179 |
+
"Organization",
|
| 180 |
+
"SearchOrganizationsRequest",
|
| 181 |
+
"SearchOrganizationsResponse",
|
| 182 |
+
"UndeleteOrganizationMetadata",
|
| 183 |
+
"CreateProjectMetadata",
|
| 184 |
+
"CreateProjectRequest",
|
| 185 |
+
"DeleteProjectMetadata",
|
| 186 |
+
"DeleteProjectRequest",
|
| 187 |
+
"GetProjectRequest",
|
| 188 |
+
"ListProjectsRequest",
|
| 189 |
+
"ListProjectsResponse",
|
| 190 |
+
"MoveProjectMetadata",
|
| 191 |
+
"MoveProjectRequest",
|
| 192 |
+
"Project",
|
| 193 |
+
"SearchProjectsRequest",
|
| 194 |
+
"SearchProjectsResponse",
|
| 195 |
+
"UndeleteProjectMetadata",
|
| 196 |
+
"UndeleteProjectRequest",
|
| 197 |
+
"UpdateProjectMetadata",
|
| 198 |
+
"UpdateProjectRequest",
|
| 199 |
+
"CreateTagBindingMetadata",
|
| 200 |
+
"CreateTagBindingRequest",
|
| 201 |
+
"DeleteTagBindingMetadata",
|
| 202 |
+
"DeleteTagBindingRequest",
|
| 203 |
+
"EffectiveTag",
|
| 204 |
+
"ListEffectiveTagsRequest",
|
| 205 |
+
"ListEffectiveTagsResponse",
|
| 206 |
+
"ListTagBindingsRequest",
|
| 207 |
+
"ListTagBindingsResponse",
|
| 208 |
+
"TagBinding",
|
| 209 |
+
"CreateTagHoldMetadata",
|
| 210 |
+
"CreateTagHoldRequest",
|
| 211 |
+
"DeleteTagHoldMetadata",
|
| 212 |
+
"DeleteTagHoldRequest",
|
| 213 |
+
"ListTagHoldsRequest",
|
| 214 |
+
"ListTagHoldsResponse",
|
| 215 |
+
"TagHold",
|
| 216 |
+
"CreateTagKeyMetadata",
|
| 217 |
+
"CreateTagKeyRequest",
|
| 218 |
+
"DeleteTagKeyMetadata",
|
| 219 |
+
"DeleteTagKeyRequest",
|
| 220 |
+
"GetNamespacedTagKeyRequest",
|
| 221 |
+
"GetTagKeyRequest",
|
| 222 |
+
"ListTagKeysRequest",
|
| 223 |
+
"ListTagKeysResponse",
|
| 224 |
+
"TagKey",
|
| 225 |
+
"UpdateTagKeyMetadata",
|
| 226 |
+
"UpdateTagKeyRequest",
|
| 227 |
+
"Purpose",
|
| 228 |
+
"CreateTagValueMetadata",
|
| 229 |
+
"CreateTagValueRequest",
|
| 230 |
+
"DeleteTagValueMetadata",
|
| 231 |
+
"DeleteTagValueRequest",
|
| 232 |
+
"GetNamespacedTagValueRequest",
|
| 233 |
+
"GetTagValueRequest",
|
| 234 |
+
"ListTagValuesRequest",
|
| 235 |
+
"ListTagValuesResponse",
|
| 236 |
+
"TagValue",
|
| 237 |
+
"UpdateTagValueMetadata",
|
| 238 |
+
"UpdateTagValueRequest",
|
| 239 |
+
)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (5.24 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/__pycache__/gapic_version.cpython-312.pyc
ADDED
|
Binary file (239 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/gapic_version.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
__version__ = "1.17.0" # {x-release-please-version}
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager/py.typed
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Marker file for PEP 561.
|
| 2 |
+
# The google-cloud-resource-manager package uses inline types.
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/__init__.py
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
import sys
|
| 17 |
+
|
| 18 |
+
import google.api_core as api_core
|
| 19 |
+
|
| 20 |
+
from google.cloud.resourcemanager_v3 import gapic_version as package_version
|
| 21 |
+
|
| 22 |
+
__version__ = package_version.__version__
|
| 23 |
+
|
| 24 |
+
if sys.version_info >= (3, 8): # pragma: NO COVER
|
| 25 |
+
from importlib import metadata
|
| 26 |
+
else: # pragma: NO COVER
|
| 27 |
+
# TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
|
| 28 |
+
# this code path once we drop support for Python 3.7
|
| 29 |
+
import importlib_metadata as metadata
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
from .services.folders import FoldersAsyncClient, FoldersClient
|
| 33 |
+
from .services.organizations import OrganizationsAsyncClient, OrganizationsClient
|
| 34 |
+
from .services.projects import ProjectsAsyncClient, ProjectsClient
|
| 35 |
+
from .services.tag_bindings import TagBindingsAsyncClient, TagBindingsClient
|
| 36 |
+
from .services.tag_holds import TagHoldsAsyncClient, TagHoldsClient
|
| 37 |
+
from .services.tag_keys import TagKeysAsyncClient, TagKeysClient
|
| 38 |
+
from .services.tag_values import TagValuesAsyncClient, TagValuesClient
|
| 39 |
+
from .types.folders import (
|
| 40 |
+
CreateFolderMetadata,
|
| 41 |
+
CreateFolderRequest,
|
| 42 |
+
DeleteFolderMetadata,
|
| 43 |
+
DeleteFolderRequest,
|
| 44 |
+
Folder,
|
| 45 |
+
GetFolderRequest,
|
| 46 |
+
ListFoldersRequest,
|
| 47 |
+
ListFoldersResponse,
|
| 48 |
+
MoveFolderMetadata,
|
| 49 |
+
MoveFolderRequest,
|
| 50 |
+
SearchFoldersRequest,
|
| 51 |
+
SearchFoldersResponse,
|
| 52 |
+
UndeleteFolderMetadata,
|
| 53 |
+
UndeleteFolderRequest,
|
| 54 |
+
UpdateFolderMetadata,
|
| 55 |
+
UpdateFolderRequest,
|
| 56 |
+
)
|
| 57 |
+
from .types.organizations import (
|
| 58 |
+
DeleteOrganizationMetadata,
|
| 59 |
+
GetOrganizationRequest,
|
| 60 |
+
Organization,
|
| 61 |
+
SearchOrganizationsRequest,
|
| 62 |
+
SearchOrganizationsResponse,
|
| 63 |
+
UndeleteOrganizationMetadata,
|
| 64 |
+
)
|
| 65 |
+
from .types.projects import (
|
| 66 |
+
CreateProjectMetadata,
|
| 67 |
+
CreateProjectRequest,
|
| 68 |
+
DeleteProjectMetadata,
|
| 69 |
+
DeleteProjectRequest,
|
| 70 |
+
GetProjectRequest,
|
| 71 |
+
ListProjectsRequest,
|
| 72 |
+
ListProjectsResponse,
|
| 73 |
+
MoveProjectMetadata,
|
| 74 |
+
MoveProjectRequest,
|
| 75 |
+
Project,
|
| 76 |
+
SearchProjectsRequest,
|
| 77 |
+
SearchProjectsResponse,
|
| 78 |
+
UndeleteProjectMetadata,
|
| 79 |
+
UndeleteProjectRequest,
|
| 80 |
+
UpdateProjectMetadata,
|
| 81 |
+
UpdateProjectRequest,
|
| 82 |
+
)
|
| 83 |
+
from .types.tag_bindings import (
|
| 84 |
+
CreateTagBindingMetadata,
|
| 85 |
+
CreateTagBindingRequest,
|
| 86 |
+
DeleteTagBindingMetadata,
|
| 87 |
+
DeleteTagBindingRequest,
|
| 88 |
+
EffectiveTag,
|
| 89 |
+
ListEffectiveTagsRequest,
|
| 90 |
+
ListEffectiveTagsResponse,
|
| 91 |
+
ListTagBindingsRequest,
|
| 92 |
+
ListTagBindingsResponse,
|
| 93 |
+
TagBinding,
|
| 94 |
+
)
|
| 95 |
+
from .types.tag_holds import (
|
| 96 |
+
CreateTagHoldMetadata,
|
| 97 |
+
CreateTagHoldRequest,
|
| 98 |
+
DeleteTagHoldMetadata,
|
| 99 |
+
DeleteTagHoldRequest,
|
| 100 |
+
ListTagHoldsRequest,
|
| 101 |
+
ListTagHoldsResponse,
|
| 102 |
+
TagHold,
|
| 103 |
+
)
|
| 104 |
+
from .types.tag_keys import (
|
| 105 |
+
CreateTagKeyMetadata,
|
| 106 |
+
CreateTagKeyRequest,
|
| 107 |
+
DeleteTagKeyMetadata,
|
| 108 |
+
DeleteTagKeyRequest,
|
| 109 |
+
GetNamespacedTagKeyRequest,
|
| 110 |
+
GetTagKeyRequest,
|
| 111 |
+
ListTagKeysRequest,
|
| 112 |
+
ListTagKeysResponse,
|
| 113 |
+
Purpose,
|
| 114 |
+
TagKey,
|
| 115 |
+
UpdateTagKeyMetadata,
|
| 116 |
+
UpdateTagKeyRequest,
|
| 117 |
+
)
|
| 118 |
+
from .types.tag_values import (
|
| 119 |
+
CreateTagValueMetadata,
|
| 120 |
+
CreateTagValueRequest,
|
| 121 |
+
DeleteTagValueMetadata,
|
| 122 |
+
DeleteTagValueRequest,
|
| 123 |
+
GetNamespacedTagValueRequest,
|
| 124 |
+
GetTagValueRequest,
|
| 125 |
+
ListTagValuesRequest,
|
| 126 |
+
ListTagValuesResponse,
|
| 127 |
+
TagValue,
|
| 128 |
+
UpdateTagValueMetadata,
|
| 129 |
+
UpdateTagValueRequest,
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
if hasattr(api_core, "check_python_version") and hasattr(
|
| 133 |
+
api_core, "check_dependency_versions"
|
| 134 |
+
): # pragma: NO COVER
|
| 135 |
+
api_core.check_python_version("google.cloud.resourcemanager_v3") # type: ignore
|
| 136 |
+
api_core.check_dependency_versions("google.cloud.resourcemanager_v3") # type: ignore
|
| 137 |
+
else: # pragma: NO COVER
|
| 138 |
+
# An older version of api_core is installed which does not define the
|
| 139 |
+
# functions above. We do equivalent checks manually.
|
| 140 |
+
try:
|
| 141 |
+
import sys
|
| 142 |
+
import warnings
|
| 143 |
+
|
| 144 |
+
_py_version_str = sys.version.split()[0]
|
| 145 |
+
_package_label = "google.cloud.resourcemanager_v3"
|
| 146 |
+
if sys.version_info < (3, 9):
|
| 147 |
+
warnings.warn(
|
| 148 |
+
"You are using a non-supported Python version "
|
| 149 |
+
+ f"({_py_version_str}). Google will not post any further "
|
| 150 |
+
+ f"updates to {_package_label} supporting this Python version. "
|
| 151 |
+
+ "Please upgrade to the latest Python version, or at "
|
| 152 |
+
+ f"least to Python 3.9, and then update {_package_label}.",
|
| 153 |
+
FutureWarning,
|
| 154 |
+
)
|
| 155 |
+
if sys.version_info[:2] == (3, 9):
|
| 156 |
+
warnings.warn(
|
| 157 |
+
f"You are using a Python version ({_py_version_str}) "
|
| 158 |
+
+ f"which Google will stop supporting in {_package_label} in "
|
| 159 |
+
+ "January 2026. Please "
|
| 160 |
+
+ "upgrade to the latest Python version, or at "
|
| 161 |
+
+ "least to Python 3.10, before then, and "
|
| 162 |
+
+ f"then update {_package_label}.",
|
| 163 |
+
FutureWarning,
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
def parse_version_to_tuple(version_string: str):
|
| 167 |
+
"""Safely converts a semantic version string to a comparable tuple of integers.
|
| 168 |
+
Example: "4.25.8" -> (4, 25, 8)
|
| 169 |
+
Ignores non-numeric parts and handles common version formats.
|
| 170 |
+
Args:
|
| 171 |
+
version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
|
| 172 |
+
Returns:
|
| 173 |
+
Tuple of integers for the parsed version string.
|
| 174 |
+
"""
|
| 175 |
+
parts = []
|
| 176 |
+
for part in version_string.split("."):
|
| 177 |
+
try:
|
| 178 |
+
parts.append(int(part))
|
| 179 |
+
except ValueError:
|
| 180 |
+
# If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
|
| 181 |
+
# This is a simplification compared to 'packaging.parse_version', but sufficient
|
| 182 |
+
# for comparing strictly numeric semantic versions.
|
| 183 |
+
break
|
| 184 |
+
return tuple(parts)
|
| 185 |
+
|
| 186 |
+
def _get_version(dependency_name):
|
| 187 |
+
try:
|
| 188 |
+
version_string: str = metadata.version(dependency_name)
|
| 189 |
+
parsed_version = parse_version_to_tuple(version_string)
|
| 190 |
+
return (parsed_version, version_string)
|
| 191 |
+
except Exception:
|
| 192 |
+
# Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
|
| 193 |
+
# or errors during parse_version_to_tuple
|
| 194 |
+
return (None, "--")
|
| 195 |
+
|
| 196 |
+
_dependency_package = "google.protobuf"
|
| 197 |
+
_next_supported_version = "4.25.8"
|
| 198 |
+
_next_supported_version_tuple = (4, 25, 8)
|
| 199 |
+
_recommendation = " (we recommend 6.x)"
|
| 200 |
+
(_version_used, _version_used_string) = _get_version(_dependency_package)
|
| 201 |
+
if _version_used and _version_used < _next_supported_version_tuple:
|
| 202 |
+
warnings.warn(
|
| 203 |
+
f"Package {_package_label} depends on "
|
| 204 |
+
+ f"{_dependency_package}, currently installed at version "
|
| 205 |
+
+ f"{_version_used_string}. Future updates to "
|
| 206 |
+
+ f"{_package_label} will require {_dependency_package} at "
|
| 207 |
+
+ f"version {_next_supported_version} or higher{_recommendation}."
|
| 208 |
+
+ " Please ensure "
|
| 209 |
+
+ "that either (a) your Python environment doesn't pin the "
|
| 210 |
+
+ f"version of {_dependency_package}, so that updates to "
|
| 211 |
+
+ f"{_package_label} can require the higher version, or "
|
| 212 |
+
+ "(b) you manually update your Python environment to use at "
|
| 213 |
+
+ f"least version {_next_supported_version} of "
|
| 214 |
+
+ f"{_dependency_package}.",
|
| 215 |
+
FutureWarning,
|
| 216 |
+
)
|
| 217 |
+
except Exception:
|
| 218 |
+
warnings.warn(
|
| 219 |
+
"Could not determine the version of Python "
|
| 220 |
+
+ "currently being used. To continue receiving "
|
| 221 |
+
+ "updates for {_package_label}, ensure you are "
|
| 222 |
+
+ "using a supported version of Python; see "
|
| 223 |
+
+ "https://devguide.python.org/versions/"
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
__all__ = (
|
| 227 |
+
"FoldersAsyncClient",
|
| 228 |
+
"OrganizationsAsyncClient",
|
| 229 |
+
"ProjectsAsyncClient",
|
| 230 |
+
"TagBindingsAsyncClient",
|
| 231 |
+
"TagHoldsAsyncClient",
|
| 232 |
+
"TagKeysAsyncClient",
|
| 233 |
+
"TagValuesAsyncClient",
|
| 234 |
+
"CreateFolderMetadata",
|
| 235 |
+
"CreateFolderRequest",
|
| 236 |
+
"CreateProjectMetadata",
|
| 237 |
+
"CreateProjectRequest",
|
| 238 |
+
"CreateTagBindingMetadata",
|
| 239 |
+
"CreateTagBindingRequest",
|
| 240 |
+
"CreateTagHoldMetadata",
|
| 241 |
+
"CreateTagHoldRequest",
|
| 242 |
+
"CreateTagKeyMetadata",
|
| 243 |
+
"CreateTagKeyRequest",
|
| 244 |
+
"CreateTagValueMetadata",
|
| 245 |
+
"CreateTagValueRequest",
|
| 246 |
+
"DeleteFolderMetadata",
|
| 247 |
+
"DeleteFolderRequest",
|
| 248 |
+
"DeleteOrganizationMetadata",
|
| 249 |
+
"DeleteProjectMetadata",
|
| 250 |
+
"DeleteProjectRequest",
|
| 251 |
+
"DeleteTagBindingMetadata",
|
| 252 |
+
"DeleteTagBindingRequest",
|
| 253 |
+
"DeleteTagHoldMetadata",
|
| 254 |
+
"DeleteTagHoldRequest",
|
| 255 |
+
"DeleteTagKeyMetadata",
|
| 256 |
+
"DeleteTagKeyRequest",
|
| 257 |
+
"DeleteTagValueMetadata",
|
| 258 |
+
"DeleteTagValueRequest",
|
| 259 |
+
"EffectiveTag",
|
| 260 |
+
"Folder",
|
| 261 |
+
"FoldersClient",
|
| 262 |
+
"GetFolderRequest",
|
| 263 |
+
"GetNamespacedTagKeyRequest",
|
| 264 |
+
"GetNamespacedTagValueRequest",
|
| 265 |
+
"GetOrganizationRequest",
|
| 266 |
+
"GetProjectRequest",
|
| 267 |
+
"GetTagKeyRequest",
|
| 268 |
+
"GetTagValueRequest",
|
| 269 |
+
"ListEffectiveTagsRequest",
|
| 270 |
+
"ListEffectiveTagsResponse",
|
| 271 |
+
"ListFoldersRequest",
|
| 272 |
+
"ListFoldersResponse",
|
| 273 |
+
"ListProjectsRequest",
|
| 274 |
+
"ListProjectsResponse",
|
| 275 |
+
"ListTagBindingsRequest",
|
| 276 |
+
"ListTagBindingsResponse",
|
| 277 |
+
"ListTagHoldsRequest",
|
| 278 |
+
"ListTagHoldsResponse",
|
| 279 |
+
"ListTagKeysRequest",
|
| 280 |
+
"ListTagKeysResponse",
|
| 281 |
+
"ListTagValuesRequest",
|
| 282 |
+
"ListTagValuesResponse",
|
| 283 |
+
"MoveFolderMetadata",
|
| 284 |
+
"MoveFolderRequest",
|
| 285 |
+
"MoveProjectMetadata",
|
| 286 |
+
"MoveProjectRequest",
|
| 287 |
+
"Organization",
|
| 288 |
+
"OrganizationsClient",
|
| 289 |
+
"Project",
|
| 290 |
+
"ProjectsClient",
|
| 291 |
+
"Purpose",
|
| 292 |
+
"SearchFoldersRequest",
|
| 293 |
+
"SearchFoldersResponse",
|
| 294 |
+
"SearchOrganizationsRequest",
|
| 295 |
+
"SearchOrganizationsResponse",
|
| 296 |
+
"SearchProjectsRequest",
|
| 297 |
+
"SearchProjectsResponse",
|
| 298 |
+
"TagBinding",
|
| 299 |
+
"TagBindingsClient",
|
| 300 |
+
"TagHold",
|
| 301 |
+
"TagHoldsClient",
|
| 302 |
+
"TagKey",
|
| 303 |
+
"TagKeysClient",
|
| 304 |
+
"TagValue",
|
| 305 |
+
"TagValuesClient",
|
| 306 |
+
"UndeleteFolderMetadata",
|
| 307 |
+
"UndeleteFolderRequest",
|
| 308 |
+
"UndeleteOrganizationMetadata",
|
| 309 |
+
"UndeleteProjectMetadata",
|
| 310 |
+
"UndeleteProjectRequest",
|
| 311 |
+
"UpdateFolderMetadata",
|
| 312 |
+
"UpdateFolderRequest",
|
| 313 |
+
"UpdateProjectMetadata",
|
| 314 |
+
"UpdateProjectRequest",
|
| 315 |
+
"UpdateTagKeyMetadata",
|
| 316 |
+
"UpdateTagKeyRequest",
|
| 317 |
+
"UpdateTagValueMetadata",
|
| 318 |
+
"UpdateTagValueRequest",
|
| 319 |
+
)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (8.45 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/__pycache__/gapic_version.cpython-312.pyc
ADDED
|
Binary file (242 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/gapic_metadata.json
ADDED
|
@@ -0,0 +1,922 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"comment": "This file maps proto services/RPCs to the corresponding library clients/methods",
|
| 3 |
+
"language": "python",
|
| 4 |
+
"libraryPackage": "google.cloud.resourcemanager_v3",
|
| 5 |
+
"protoPackage": "google.cloud.resourcemanager.v3",
|
| 6 |
+
"schema": "1.0",
|
| 7 |
+
"services": {
|
| 8 |
+
"Folders": {
|
| 9 |
+
"clients": {
|
| 10 |
+
"grpc": {
|
| 11 |
+
"libraryClient": "FoldersClient",
|
| 12 |
+
"rpcs": {
|
| 13 |
+
"CreateFolder": {
|
| 14 |
+
"methods": [
|
| 15 |
+
"create_folder"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
"DeleteFolder": {
|
| 19 |
+
"methods": [
|
| 20 |
+
"delete_folder"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
"GetFolder": {
|
| 24 |
+
"methods": [
|
| 25 |
+
"get_folder"
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
"GetIamPolicy": {
|
| 29 |
+
"methods": [
|
| 30 |
+
"get_iam_policy"
|
| 31 |
+
]
|
| 32 |
+
},
|
| 33 |
+
"ListFolders": {
|
| 34 |
+
"methods": [
|
| 35 |
+
"list_folders"
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
"MoveFolder": {
|
| 39 |
+
"methods": [
|
| 40 |
+
"move_folder"
|
| 41 |
+
]
|
| 42 |
+
},
|
| 43 |
+
"SearchFolders": {
|
| 44 |
+
"methods": [
|
| 45 |
+
"search_folders"
|
| 46 |
+
]
|
| 47 |
+
},
|
| 48 |
+
"SetIamPolicy": {
|
| 49 |
+
"methods": [
|
| 50 |
+
"set_iam_policy"
|
| 51 |
+
]
|
| 52 |
+
},
|
| 53 |
+
"TestIamPermissions": {
|
| 54 |
+
"methods": [
|
| 55 |
+
"test_iam_permissions"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
"UndeleteFolder": {
|
| 59 |
+
"methods": [
|
| 60 |
+
"undelete_folder"
|
| 61 |
+
]
|
| 62 |
+
},
|
| 63 |
+
"UpdateFolder": {
|
| 64 |
+
"methods": [
|
| 65 |
+
"update_folder"
|
| 66 |
+
]
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
},
|
| 70 |
+
"grpc-async": {
|
| 71 |
+
"libraryClient": "FoldersAsyncClient",
|
| 72 |
+
"rpcs": {
|
| 73 |
+
"CreateFolder": {
|
| 74 |
+
"methods": [
|
| 75 |
+
"create_folder"
|
| 76 |
+
]
|
| 77 |
+
},
|
| 78 |
+
"DeleteFolder": {
|
| 79 |
+
"methods": [
|
| 80 |
+
"delete_folder"
|
| 81 |
+
]
|
| 82 |
+
},
|
| 83 |
+
"GetFolder": {
|
| 84 |
+
"methods": [
|
| 85 |
+
"get_folder"
|
| 86 |
+
]
|
| 87 |
+
},
|
| 88 |
+
"GetIamPolicy": {
|
| 89 |
+
"methods": [
|
| 90 |
+
"get_iam_policy"
|
| 91 |
+
]
|
| 92 |
+
},
|
| 93 |
+
"ListFolders": {
|
| 94 |
+
"methods": [
|
| 95 |
+
"list_folders"
|
| 96 |
+
]
|
| 97 |
+
},
|
| 98 |
+
"MoveFolder": {
|
| 99 |
+
"methods": [
|
| 100 |
+
"move_folder"
|
| 101 |
+
]
|
| 102 |
+
},
|
| 103 |
+
"SearchFolders": {
|
| 104 |
+
"methods": [
|
| 105 |
+
"search_folders"
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
"SetIamPolicy": {
|
| 109 |
+
"methods": [
|
| 110 |
+
"set_iam_policy"
|
| 111 |
+
]
|
| 112 |
+
},
|
| 113 |
+
"TestIamPermissions": {
|
| 114 |
+
"methods": [
|
| 115 |
+
"test_iam_permissions"
|
| 116 |
+
]
|
| 117 |
+
},
|
| 118 |
+
"UndeleteFolder": {
|
| 119 |
+
"methods": [
|
| 120 |
+
"undelete_folder"
|
| 121 |
+
]
|
| 122 |
+
},
|
| 123 |
+
"UpdateFolder": {
|
| 124 |
+
"methods": [
|
| 125 |
+
"update_folder"
|
| 126 |
+
]
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
},
|
| 130 |
+
"rest": {
|
| 131 |
+
"libraryClient": "FoldersClient",
|
| 132 |
+
"rpcs": {
|
| 133 |
+
"CreateFolder": {
|
| 134 |
+
"methods": [
|
| 135 |
+
"create_folder"
|
| 136 |
+
]
|
| 137 |
+
},
|
| 138 |
+
"DeleteFolder": {
|
| 139 |
+
"methods": [
|
| 140 |
+
"delete_folder"
|
| 141 |
+
]
|
| 142 |
+
},
|
| 143 |
+
"GetFolder": {
|
| 144 |
+
"methods": [
|
| 145 |
+
"get_folder"
|
| 146 |
+
]
|
| 147 |
+
},
|
| 148 |
+
"GetIamPolicy": {
|
| 149 |
+
"methods": [
|
| 150 |
+
"get_iam_policy"
|
| 151 |
+
]
|
| 152 |
+
},
|
| 153 |
+
"ListFolders": {
|
| 154 |
+
"methods": [
|
| 155 |
+
"list_folders"
|
| 156 |
+
]
|
| 157 |
+
},
|
| 158 |
+
"MoveFolder": {
|
| 159 |
+
"methods": [
|
| 160 |
+
"move_folder"
|
| 161 |
+
]
|
| 162 |
+
},
|
| 163 |
+
"SearchFolders": {
|
| 164 |
+
"methods": [
|
| 165 |
+
"search_folders"
|
| 166 |
+
]
|
| 167 |
+
},
|
| 168 |
+
"SetIamPolicy": {
|
| 169 |
+
"methods": [
|
| 170 |
+
"set_iam_policy"
|
| 171 |
+
]
|
| 172 |
+
},
|
| 173 |
+
"TestIamPermissions": {
|
| 174 |
+
"methods": [
|
| 175 |
+
"test_iam_permissions"
|
| 176 |
+
]
|
| 177 |
+
},
|
| 178 |
+
"UndeleteFolder": {
|
| 179 |
+
"methods": [
|
| 180 |
+
"undelete_folder"
|
| 181 |
+
]
|
| 182 |
+
},
|
| 183 |
+
"UpdateFolder": {
|
| 184 |
+
"methods": [
|
| 185 |
+
"update_folder"
|
| 186 |
+
]
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
},
|
| 192 |
+
"Organizations": {
|
| 193 |
+
"clients": {
|
| 194 |
+
"grpc": {
|
| 195 |
+
"libraryClient": "OrganizationsClient",
|
| 196 |
+
"rpcs": {
|
| 197 |
+
"GetIamPolicy": {
|
| 198 |
+
"methods": [
|
| 199 |
+
"get_iam_policy"
|
| 200 |
+
]
|
| 201 |
+
},
|
| 202 |
+
"GetOrganization": {
|
| 203 |
+
"methods": [
|
| 204 |
+
"get_organization"
|
| 205 |
+
]
|
| 206 |
+
},
|
| 207 |
+
"SearchOrganizations": {
|
| 208 |
+
"methods": [
|
| 209 |
+
"search_organizations"
|
| 210 |
+
]
|
| 211 |
+
},
|
| 212 |
+
"SetIamPolicy": {
|
| 213 |
+
"methods": [
|
| 214 |
+
"set_iam_policy"
|
| 215 |
+
]
|
| 216 |
+
},
|
| 217 |
+
"TestIamPermissions": {
|
| 218 |
+
"methods": [
|
| 219 |
+
"test_iam_permissions"
|
| 220 |
+
]
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
},
|
| 224 |
+
"grpc-async": {
|
| 225 |
+
"libraryClient": "OrganizationsAsyncClient",
|
| 226 |
+
"rpcs": {
|
| 227 |
+
"GetIamPolicy": {
|
| 228 |
+
"methods": [
|
| 229 |
+
"get_iam_policy"
|
| 230 |
+
]
|
| 231 |
+
},
|
| 232 |
+
"GetOrganization": {
|
| 233 |
+
"methods": [
|
| 234 |
+
"get_organization"
|
| 235 |
+
]
|
| 236 |
+
},
|
| 237 |
+
"SearchOrganizations": {
|
| 238 |
+
"methods": [
|
| 239 |
+
"search_organizations"
|
| 240 |
+
]
|
| 241 |
+
},
|
| 242 |
+
"SetIamPolicy": {
|
| 243 |
+
"methods": [
|
| 244 |
+
"set_iam_policy"
|
| 245 |
+
]
|
| 246 |
+
},
|
| 247 |
+
"TestIamPermissions": {
|
| 248 |
+
"methods": [
|
| 249 |
+
"test_iam_permissions"
|
| 250 |
+
]
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
},
|
| 254 |
+
"rest": {
|
| 255 |
+
"libraryClient": "OrganizationsClient",
|
| 256 |
+
"rpcs": {
|
| 257 |
+
"GetIamPolicy": {
|
| 258 |
+
"methods": [
|
| 259 |
+
"get_iam_policy"
|
| 260 |
+
]
|
| 261 |
+
},
|
| 262 |
+
"GetOrganization": {
|
| 263 |
+
"methods": [
|
| 264 |
+
"get_organization"
|
| 265 |
+
]
|
| 266 |
+
},
|
| 267 |
+
"SearchOrganizations": {
|
| 268 |
+
"methods": [
|
| 269 |
+
"search_organizations"
|
| 270 |
+
]
|
| 271 |
+
},
|
| 272 |
+
"SetIamPolicy": {
|
| 273 |
+
"methods": [
|
| 274 |
+
"set_iam_policy"
|
| 275 |
+
]
|
| 276 |
+
},
|
| 277 |
+
"TestIamPermissions": {
|
| 278 |
+
"methods": [
|
| 279 |
+
"test_iam_permissions"
|
| 280 |
+
]
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
}
|
| 285 |
+
},
|
| 286 |
+
"Projects": {
|
| 287 |
+
"clients": {
|
| 288 |
+
"grpc": {
|
| 289 |
+
"libraryClient": "ProjectsClient",
|
| 290 |
+
"rpcs": {
|
| 291 |
+
"CreateProject": {
|
| 292 |
+
"methods": [
|
| 293 |
+
"create_project"
|
| 294 |
+
]
|
| 295 |
+
},
|
| 296 |
+
"DeleteProject": {
|
| 297 |
+
"methods": [
|
| 298 |
+
"delete_project"
|
| 299 |
+
]
|
| 300 |
+
},
|
| 301 |
+
"GetIamPolicy": {
|
| 302 |
+
"methods": [
|
| 303 |
+
"get_iam_policy"
|
| 304 |
+
]
|
| 305 |
+
},
|
| 306 |
+
"GetProject": {
|
| 307 |
+
"methods": [
|
| 308 |
+
"get_project"
|
| 309 |
+
]
|
| 310 |
+
},
|
| 311 |
+
"ListProjects": {
|
| 312 |
+
"methods": [
|
| 313 |
+
"list_projects"
|
| 314 |
+
]
|
| 315 |
+
},
|
| 316 |
+
"MoveProject": {
|
| 317 |
+
"methods": [
|
| 318 |
+
"move_project"
|
| 319 |
+
]
|
| 320 |
+
},
|
| 321 |
+
"SearchProjects": {
|
| 322 |
+
"methods": [
|
| 323 |
+
"search_projects"
|
| 324 |
+
]
|
| 325 |
+
},
|
| 326 |
+
"SetIamPolicy": {
|
| 327 |
+
"methods": [
|
| 328 |
+
"set_iam_policy"
|
| 329 |
+
]
|
| 330 |
+
},
|
| 331 |
+
"TestIamPermissions": {
|
| 332 |
+
"methods": [
|
| 333 |
+
"test_iam_permissions"
|
| 334 |
+
]
|
| 335 |
+
},
|
| 336 |
+
"UndeleteProject": {
|
| 337 |
+
"methods": [
|
| 338 |
+
"undelete_project"
|
| 339 |
+
]
|
| 340 |
+
},
|
| 341 |
+
"UpdateProject": {
|
| 342 |
+
"methods": [
|
| 343 |
+
"update_project"
|
| 344 |
+
]
|
| 345 |
+
}
|
| 346 |
+
}
|
| 347 |
+
},
|
| 348 |
+
"grpc-async": {
|
| 349 |
+
"libraryClient": "ProjectsAsyncClient",
|
| 350 |
+
"rpcs": {
|
| 351 |
+
"CreateProject": {
|
| 352 |
+
"methods": [
|
| 353 |
+
"create_project"
|
| 354 |
+
]
|
| 355 |
+
},
|
| 356 |
+
"DeleteProject": {
|
| 357 |
+
"methods": [
|
| 358 |
+
"delete_project"
|
| 359 |
+
]
|
| 360 |
+
},
|
| 361 |
+
"GetIamPolicy": {
|
| 362 |
+
"methods": [
|
| 363 |
+
"get_iam_policy"
|
| 364 |
+
]
|
| 365 |
+
},
|
| 366 |
+
"GetProject": {
|
| 367 |
+
"methods": [
|
| 368 |
+
"get_project"
|
| 369 |
+
]
|
| 370 |
+
},
|
| 371 |
+
"ListProjects": {
|
| 372 |
+
"methods": [
|
| 373 |
+
"list_projects"
|
| 374 |
+
]
|
| 375 |
+
},
|
| 376 |
+
"MoveProject": {
|
| 377 |
+
"methods": [
|
| 378 |
+
"move_project"
|
| 379 |
+
]
|
| 380 |
+
},
|
| 381 |
+
"SearchProjects": {
|
| 382 |
+
"methods": [
|
| 383 |
+
"search_projects"
|
| 384 |
+
]
|
| 385 |
+
},
|
| 386 |
+
"SetIamPolicy": {
|
| 387 |
+
"methods": [
|
| 388 |
+
"set_iam_policy"
|
| 389 |
+
]
|
| 390 |
+
},
|
| 391 |
+
"TestIamPermissions": {
|
| 392 |
+
"methods": [
|
| 393 |
+
"test_iam_permissions"
|
| 394 |
+
]
|
| 395 |
+
},
|
| 396 |
+
"UndeleteProject": {
|
| 397 |
+
"methods": [
|
| 398 |
+
"undelete_project"
|
| 399 |
+
]
|
| 400 |
+
},
|
| 401 |
+
"UpdateProject": {
|
| 402 |
+
"methods": [
|
| 403 |
+
"update_project"
|
| 404 |
+
]
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
},
|
| 408 |
+
"rest": {
|
| 409 |
+
"libraryClient": "ProjectsClient",
|
| 410 |
+
"rpcs": {
|
| 411 |
+
"CreateProject": {
|
| 412 |
+
"methods": [
|
| 413 |
+
"create_project"
|
| 414 |
+
]
|
| 415 |
+
},
|
| 416 |
+
"DeleteProject": {
|
| 417 |
+
"methods": [
|
| 418 |
+
"delete_project"
|
| 419 |
+
]
|
| 420 |
+
},
|
| 421 |
+
"GetIamPolicy": {
|
| 422 |
+
"methods": [
|
| 423 |
+
"get_iam_policy"
|
| 424 |
+
]
|
| 425 |
+
},
|
| 426 |
+
"GetProject": {
|
| 427 |
+
"methods": [
|
| 428 |
+
"get_project"
|
| 429 |
+
]
|
| 430 |
+
},
|
| 431 |
+
"ListProjects": {
|
| 432 |
+
"methods": [
|
| 433 |
+
"list_projects"
|
| 434 |
+
]
|
| 435 |
+
},
|
| 436 |
+
"MoveProject": {
|
| 437 |
+
"methods": [
|
| 438 |
+
"move_project"
|
| 439 |
+
]
|
| 440 |
+
},
|
| 441 |
+
"SearchProjects": {
|
| 442 |
+
"methods": [
|
| 443 |
+
"search_projects"
|
| 444 |
+
]
|
| 445 |
+
},
|
| 446 |
+
"SetIamPolicy": {
|
| 447 |
+
"methods": [
|
| 448 |
+
"set_iam_policy"
|
| 449 |
+
]
|
| 450 |
+
},
|
| 451 |
+
"TestIamPermissions": {
|
| 452 |
+
"methods": [
|
| 453 |
+
"test_iam_permissions"
|
| 454 |
+
]
|
| 455 |
+
},
|
| 456 |
+
"UndeleteProject": {
|
| 457 |
+
"methods": [
|
| 458 |
+
"undelete_project"
|
| 459 |
+
]
|
| 460 |
+
},
|
| 461 |
+
"UpdateProject": {
|
| 462 |
+
"methods": [
|
| 463 |
+
"update_project"
|
| 464 |
+
]
|
| 465 |
+
}
|
| 466 |
+
}
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
},
|
| 470 |
+
"TagBindings": {
|
| 471 |
+
"clients": {
|
| 472 |
+
"grpc": {
|
| 473 |
+
"libraryClient": "TagBindingsClient",
|
| 474 |
+
"rpcs": {
|
| 475 |
+
"CreateTagBinding": {
|
| 476 |
+
"methods": [
|
| 477 |
+
"create_tag_binding"
|
| 478 |
+
]
|
| 479 |
+
},
|
| 480 |
+
"DeleteTagBinding": {
|
| 481 |
+
"methods": [
|
| 482 |
+
"delete_tag_binding"
|
| 483 |
+
]
|
| 484 |
+
},
|
| 485 |
+
"ListEffectiveTags": {
|
| 486 |
+
"methods": [
|
| 487 |
+
"list_effective_tags"
|
| 488 |
+
]
|
| 489 |
+
},
|
| 490 |
+
"ListTagBindings": {
|
| 491 |
+
"methods": [
|
| 492 |
+
"list_tag_bindings"
|
| 493 |
+
]
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
},
|
| 497 |
+
"grpc-async": {
|
| 498 |
+
"libraryClient": "TagBindingsAsyncClient",
|
| 499 |
+
"rpcs": {
|
| 500 |
+
"CreateTagBinding": {
|
| 501 |
+
"methods": [
|
| 502 |
+
"create_tag_binding"
|
| 503 |
+
]
|
| 504 |
+
},
|
| 505 |
+
"DeleteTagBinding": {
|
| 506 |
+
"methods": [
|
| 507 |
+
"delete_tag_binding"
|
| 508 |
+
]
|
| 509 |
+
},
|
| 510 |
+
"ListEffectiveTags": {
|
| 511 |
+
"methods": [
|
| 512 |
+
"list_effective_tags"
|
| 513 |
+
]
|
| 514 |
+
},
|
| 515 |
+
"ListTagBindings": {
|
| 516 |
+
"methods": [
|
| 517 |
+
"list_tag_bindings"
|
| 518 |
+
]
|
| 519 |
+
}
|
| 520 |
+
}
|
| 521 |
+
},
|
| 522 |
+
"rest": {
|
| 523 |
+
"libraryClient": "TagBindingsClient",
|
| 524 |
+
"rpcs": {
|
| 525 |
+
"CreateTagBinding": {
|
| 526 |
+
"methods": [
|
| 527 |
+
"create_tag_binding"
|
| 528 |
+
]
|
| 529 |
+
},
|
| 530 |
+
"DeleteTagBinding": {
|
| 531 |
+
"methods": [
|
| 532 |
+
"delete_tag_binding"
|
| 533 |
+
]
|
| 534 |
+
},
|
| 535 |
+
"ListEffectiveTags": {
|
| 536 |
+
"methods": [
|
| 537 |
+
"list_effective_tags"
|
| 538 |
+
]
|
| 539 |
+
},
|
| 540 |
+
"ListTagBindings": {
|
| 541 |
+
"methods": [
|
| 542 |
+
"list_tag_bindings"
|
| 543 |
+
]
|
| 544 |
+
}
|
| 545 |
+
}
|
| 546 |
+
}
|
| 547 |
+
}
|
| 548 |
+
},
|
| 549 |
+
"TagHolds": {
|
| 550 |
+
"clients": {
|
| 551 |
+
"grpc": {
|
| 552 |
+
"libraryClient": "TagHoldsClient",
|
| 553 |
+
"rpcs": {
|
| 554 |
+
"CreateTagHold": {
|
| 555 |
+
"methods": [
|
| 556 |
+
"create_tag_hold"
|
| 557 |
+
]
|
| 558 |
+
},
|
| 559 |
+
"DeleteTagHold": {
|
| 560 |
+
"methods": [
|
| 561 |
+
"delete_tag_hold"
|
| 562 |
+
]
|
| 563 |
+
},
|
| 564 |
+
"ListTagHolds": {
|
| 565 |
+
"methods": [
|
| 566 |
+
"list_tag_holds"
|
| 567 |
+
]
|
| 568 |
+
}
|
| 569 |
+
}
|
| 570 |
+
},
|
| 571 |
+
"grpc-async": {
|
| 572 |
+
"libraryClient": "TagHoldsAsyncClient",
|
| 573 |
+
"rpcs": {
|
| 574 |
+
"CreateTagHold": {
|
| 575 |
+
"methods": [
|
| 576 |
+
"create_tag_hold"
|
| 577 |
+
]
|
| 578 |
+
},
|
| 579 |
+
"DeleteTagHold": {
|
| 580 |
+
"methods": [
|
| 581 |
+
"delete_tag_hold"
|
| 582 |
+
]
|
| 583 |
+
},
|
| 584 |
+
"ListTagHolds": {
|
| 585 |
+
"methods": [
|
| 586 |
+
"list_tag_holds"
|
| 587 |
+
]
|
| 588 |
+
}
|
| 589 |
+
}
|
| 590 |
+
},
|
| 591 |
+
"rest": {
|
| 592 |
+
"libraryClient": "TagHoldsClient",
|
| 593 |
+
"rpcs": {
|
| 594 |
+
"CreateTagHold": {
|
| 595 |
+
"methods": [
|
| 596 |
+
"create_tag_hold"
|
| 597 |
+
]
|
| 598 |
+
},
|
| 599 |
+
"DeleteTagHold": {
|
| 600 |
+
"methods": [
|
| 601 |
+
"delete_tag_hold"
|
| 602 |
+
]
|
| 603 |
+
},
|
| 604 |
+
"ListTagHolds": {
|
| 605 |
+
"methods": [
|
| 606 |
+
"list_tag_holds"
|
| 607 |
+
]
|
| 608 |
+
}
|
| 609 |
+
}
|
| 610 |
+
}
|
| 611 |
+
}
|
| 612 |
+
},
|
| 613 |
+
"TagKeys": {
|
| 614 |
+
"clients": {
|
| 615 |
+
"grpc": {
|
| 616 |
+
"libraryClient": "TagKeysClient",
|
| 617 |
+
"rpcs": {
|
| 618 |
+
"CreateTagKey": {
|
| 619 |
+
"methods": [
|
| 620 |
+
"create_tag_key"
|
| 621 |
+
]
|
| 622 |
+
},
|
| 623 |
+
"DeleteTagKey": {
|
| 624 |
+
"methods": [
|
| 625 |
+
"delete_tag_key"
|
| 626 |
+
]
|
| 627 |
+
},
|
| 628 |
+
"GetIamPolicy": {
|
| 629 |
+
"methods": [
|
| 630 |
+
"get_iam_policy"
|
| 631 |
+
]
|
| 632 |
+
},
|
| 633 |
+
"GetNamespacedTagKey": {
|
| 634 |
+
"methods": [
|
| 635 |
+
"get_namespaced_tag_key"
|
| 636 |
+
]
|
| 637 |
+
},
|
| 638 |
+
"GetTagKey": {
|
| 639 |
+
"methods": [
|
| 640 |
+
"get_tag_key"
|
| 641 |
+
]
|
| 642 |
+
},
|
| 643 |
+
"ListTagKeys": {
|
| 644 |
+
"methods": [
|
| 645 |
+
"list_tag_keys"
|
| 646 |
+
]
|
| 647 |
+
},
|
| 648 |
+
"SetIamPolicy": {
|
| 649 |
+
"methods": [
|
| 650 |
+
"set_iam_policy"
|
| 651 |
+
]
|
| 652 |
+
},
|
| 653 |
+
"TestIamPermissions": {
|
| 654 |
+
"methods": [
|
| 655 |
+
"test_iam_permissions"
|
| 656 |
+
]
|
| 657 |
+
},
|
| 658 |
+
"UpdateTagKey": {
|
| 659 |
+
"methods": [
|
| 660 |
+
"update_tag_key"
|
| 661 |
+
]
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
},
|
| 665 |
+
"grpc-async": {
|
| 666 |
+
"libraryClient": "TagKeysAsyncClient",
|
| 667 |
+
"rpcs": {
|
| 668 |
+
"CreateTagKey": {
|
| 669 |
+
"methods": [
|
| 670 |
+
"create_tag_key"
|
| 671 |
+
]
|
| 672 |
+
},
|
| 673 |
+
"DeleteTagKey": {
|
| 674 |
+
"methods": [
|
| 675 |
+
"delete_tag_key"
|
| 676 |
+
]
|
| 677 |
+
},
|
| 678 |
+
"GetIamPolicy": {
|
| 679 |
+
"methods": [
|
| 680 |
+
"get_iam_policy"
|
| 681 |
+
]
|
| 682 |
+
},
|
| 683 |
+
"GetNamespacedTagKey": {
|
| 684 |
+
"methods": [
|
| 685 |
+
"get_namespaced_tag_key"
|
| 686 |
+
]
|
| 687 |
+
},
|
| 688 |
+
"GetTagKey": {
|
| 689 |
+
"methods": [
|
| 690 |
+
"get_tag_key"
|
| 691 |
+
]
|
| 692 |
+
},
|
| 693 |
+
"ListTagKeys": {
|
| 694 |
+
"methods": [
|
| 695 |
+
"list_tag_keys"
|
| 696 |
+
]
|
| 697 |
+
},
|
| 698 |
+
"SetIamPolicy": {
|
| 699 |
+
"methods": [
|
| 700 |
+
"set_iam_policy"
|
| 701 |
+
]
|
| 702 |
+
},
|
| 703 |
+
"TestIamPermissions": {
|
| 704 |
+
"methods": [
|
| 705 |
+
"test_iam_permissions"
|
| 706 |
+
]
|
| 707 |
+
},
|
| 708 |
+
"UpdateTagKey": {
|
| 709 |
+
"methods": [
|
| 710 |
+
"update_tag_key"
|
| 711 |
+
]
|
| 712 |
+
}
|
| 713 |
+
}
|
| 714 |
+
},
|
| 715 |
+
"rest": {
|
| 716 |
+
"libraryClient": "TagKeysClient",
|
| 717 |
+
"rpcs": {
|
| 718 |
+
"CreateTagKey": {
|
| 719 |
+
"methods": [
|
| 720 |
+
"create_tag_key"
|
| 721 |
+
]
|
| 722 |
+
},
|
| 723 |
+
"DeleteTagKey": {
|
| 724 |
+
"methods": [
|
| 725 |
+
"delete_tag_key"
|
| 726 |
+
]
|
| 727 |
+
},
|
| 728 |
+
"GetIamPolicy": {
|
| 729 |
+
"methods": [
|
| 730 |
+
"get_iam_policy"
|
| 731 |
+
]
|
| 732 |
+
},
|
| 733 |
+
"GetNamespacedTagKey": {
|
| 734 |
+
"methods": [
|
| 735 |
+
"get_namespaced_tag_key"
|
| 736 |
+
]
|
| 737 |
+
},
|
| 738 |
+
"GetTagKey": {
|
| 739 |
+
"methods": [
|
| 740 |
+
"get_tag_key"
|
| 741 |
+
]
|
| 742 |
+
},
|
| 743 |
+
"ListTagKeys": {
|
| 744 |
+
"methods": [
|
| 745 |
+
"list_tag_keys"
|
| 746 |
+
]
|
| 747 |
+
},
|
| 748 |
+
"SetIamPolicy": {
|
| 749 |
+
"methods": [
|
| 750 |
+
"set_iam_policy"
|
| 751 |
+
]
|
| 752 |
+
},
|
| 753 |
+
"TestIamPermissions": {
|
| 754 |
+
"methods": [
|
| 755 |
+
"test_iam_permissions"
|
| 756 |
+
]
|
| 757 |
+
},
|
| 758 |
+
"UpdateTagKey": {
|
| 759 |
+
"methods": [
|
| 760 |
+
"update_tag_key"
|
| 761 |
+
]
|
| 762 |
+
}
|
| 763 |
+
}
|
| 764 |
+
}
|
| 765 |
+
}
|
| 766 |
+
},
|
| 767 |
+
"TagValues": {
|
| 768 |
+
"clients": {
|
| 769 |
+
"grpc": {
|
| 770 |
+
"libraryClient": "TagValuesClient",
|
| 771 |
+
"rpcs": {
|
| 772 |
+
"CreateTagValue": {
|
| 773 |
+
"methods": [
|
| 774 |
+
"create_tag_value"
|
| 775 |
+
]
|
| 776 |
+
},
|
| 777 |
+
"DeleteTagValue": {
|
| 778 |
+
"methods": [
|
| 779 |
+
"delete_tag_value"
|
| 780 |
+
]
|
| 781 |
+
},
|
| 782 |
+
"GetIamPolicy": {
|
| 783 |
+
"methods": [
|
| 784 |
+
"get_iam_policy"
|
| 785 |
+
]
|
| 786 |
+
},
|
| 787 |
+
"GetNamespacedTagValue": {
|
| 788 |
+
"methods": [
|
| 789 |
+
"get_namespaced_tag_value"
|
| 790 |
+
]
|
| 791 |
+
},
|
| 792 |
+
"GetTagValue": {
|
| 793 |
+
"methods": [
|
| 794 |
+
"get_tag_value"
|
| 795 |
+
]
|
| 796 |
+
},
|
| 797 |
+
"ListTagValues": {
|
| 798 |
+
"methods": [
|
| 799 |
+
"list_tag_values"
|
| 800 |
+
]
|
| 801 |
+
},
|
| 802 |
+
"SetIamPolicy": {
|
| 803 |
+
"methods": [
|
| 804 |
+
"set_iam_policy"
|
| 805 |
+
]
|
| 806 |
+
},
|
| 807 |
+
"TestIamPermissions": {
|
| 808 |
+
"methods": [
|
| 809 |
+
"test_iam_permissions"
|
| 810 |
+
]
|
| 811 |
+
},
|
| 812 |
+
"UpdateTagValue": {
|
| 813 |
+
"methods": [
|
| 814 |
+
"update_tag_value"
|
| 815 |
+
]
|
| 816 |
+
}
|
| 817 |
+
}
|
| 818 |
+
},
|
| 819 |
+
"grpc-async": {
|
| 820 |
+
"libraryClient": "TagValuesAsyncClient",
|
| 821 |
+
"rpcs": {
|
| 822 |
+
"CreateTagValue": {
|
| 823 |
+
"methods": [
|
| 824 |
+
"create_tag_value"
|
| 825 |
+
]
|
| 826 |
+
},
|
| 827 |
+
"DeleteTagValue": {
|
| 828 |
+
"methods": [
|
| 829 |
+
"delete_tag_value"
|
| 830 |
+
]
|
| 831 |
+
},
|
| 832 |
+
"GetIamPolicy": {
|
| 833 |
+
"methods": [
|
| 834 |
+
"get_iam_policy"
|
| 835 |
+
]
|
| 836 |
+
},
|
| 837 |
+
"GetNamespacedTagValue": {
|
| 838 |
+
"methods": [
|
| 839 |
+
"get_namespaced_tag_value"
|
| 840 |
+
]
|
| 841 |
+
},
|
| 842 |
+
"GetTagValue": {
|
| 843 |
+
"methods": [
|
| 844 |
+
"get_tag_value"
|
| 845 |
+
]
|
| 846 |
+
},
|
| 847 |
+
"ListTagValues": {
|
| 848 |
+
"methods": [
|
| 849 |
+
"list_tag_values"
|
| 850 |
+
]
|
| 851 |
+
},
|
| 852 |
+
"SetIamPolicy": {
|
| 853 |
+
"methods": [
|
| 854 |
+
"set_iam_policy"
|
| 855 |
+
]
|
| 856 |
+
},
|
| 857 |
+
"TestIamPermissions": {
|
| 858 |
+
"methods": [
|
| 859 |
+
"test_iam_permissions"
|
| 860 |
+
]
|
| 861 |
+
},
|
| 862 |
+
"UpdateTagValue": {
|
| 863 |
+
"methods": [
|
| 864 |
+
"update_tag_value"
|
| 865 |
+
]
|
| 866 |
+
}
|
| 867 |
+
}
|
| 868 |
+
},
|
| 869 |
+
"rest": {
|
| 870 |
+
"libraryClient": "TagValuesClient",
|
| 871 |
+
"rpcs": {
|
| 872 |
+
"CreateTagValue": {
|
| 873 |
+
"methods": [
|
| 874 |
+
"create_tag_value"
|
| 875 |
+
]
|
| 876 |
+
},
|
| 877 |
+
"DeleteTagValue": {
|
| 878 |
+
"methods": [
|
| 879 |
+
"delete_tag_value"
|
| 880 |
+
]
|
| 881 |
+
},
|
| 882 |
+
"GetIamPolicy": {
|
| 883 |
+
"methods": [
|
| 884 |
+
"get_iam_policy"
|
| 885 |
+
]
|
| 886 |
+
},
|
| 887 |
+
"GetNamespacedTagValue": {
|
| 888 |
+
"methods": [
|
| 889 |
+
"get_namespaced_tag_value"
|
| 890 |
+
]
|
| 891 |
+
},
|
| 892 |
+
"GetTagValue": {
|
| 893 |
+
"methods": [
|
| 894 |
+
"get_tag_value"
|
| 895 |
+
]
|
| 896 |
+
},
|
| 897 |
+
"ListTagValues": {
|
| 898 |
+
"methods": [
|
| 899 |
+
"list_tag_values"
|
| 900 |
+
]
|
| 901 |
+
},
|
| 902 |
+
"SetIamPolicy": {
|
| 903 |
+
"methods": [
|
| 904 |
+
"set_iam_policy"
|
| 905 |
+
]
|
| 906 |
+
},
|
| 907 |
+
"TestIamPermissions": {
|
| 908 |
+
"methods": [
|
| 909 |
+
"test_iam_permissions"
|
| 910 |
+
]
|
| 911 |
+
},
|
| 912 |
+
"UpdateTagValue": {
|
| 913 |
+
"methods": [
|
| 914 |
+
"update_tag_value"
|
| 915 |
+
]
|
| 916 |
+
}
|
| 917 |
+
}
|
| 918 |
+
}
|
| 919 |
+
}
|
| 920 |
+
}
|
| 921 |
+
}
|
| 922 |
+
}
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/gapic_version.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
__version__ = "1.17.0" # {x-release-please-version}
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/py.typed
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Marker file for PEP 561.
|
| 2 |
+
# The google-cloud-resource-manager package uses inline types.
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (217 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
from .async_client import FoldersAsyncClient
|
| 17 |
+
from .client import FoldersClient
|
| 18 |
+
|
| 19 |
+
__all__ = (
|
| 20 |
+
"FoldersClient",
|
| 21 |
+
"FoldersAsyncClient",
|
| 22 |
+
)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (362 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__pycache__/async_client.cpython-312.pyc
ADDED
|
Binary file (80.8 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__pycache__/client.cpython-312.pyc
ADDED
|
Binary file (96.3 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/__pycache__/pagers.cpython-312.pyc
ADDED
|
Binary file (18 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/async_client.py
ADDED
|
@@ -0,0 +1,1930 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
import logging as std_logging
|
| 17 |
+
import re
|
| 18 |
+
from collections import OrderedDict
|
| 19 |
+
from typing import (
|
| 20 |
+
Callable,
|
| 21 |
+
Dict,
|
| 22 |
+
Mapping,
|
| 23 |
+
MutableMapping,
|
| 24 |
+
MutableSequence,
|
| 25 |
+
Optional,
|
| 26 |
+
Sequence,
|
| 27 |
+
Tuple,
|
| 28 |
+
Type,
|
| 29 |
+
Union,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
import google.protobuf
|
| 33 |
+
from google.api_core import exceptions as core_exceptions
|
| 34 |
+
from google.api_core import gapic_v1
|
| 35 |
+
from google.api_core import retry_async as retries
|
| 36 |
+
from google.api_core.client_options import ClientOptions
|
| 37 |
+
from google.auth import credentials as ga_credentials # type: ignore
|
| 38 |
+
from google.oauth2 import service_account # type: ignore
|
| 39 |
+
|
| 40 |
+
from google.cloud.resourcemanager_v3 import gapic_version as package_version
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
|
| 44 |
+
except AttributeError: # pragma: NO COVER
|
| 45 |
+
OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore
|
| 46 |
+
|
| 47 |
+
import google.api_core.operation as operation # type: ignore
|
| 48 |
+
import google.api_core.operation_async as operation_async # type: ignore
|
| 49 |
+
import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore
|
| 50 |
+
import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore
|
| 51 |
+
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
|
| 52 |
+
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
|
| 53 |
+
from google.longrunning import operations_pb2 # type: ignore
|
| 54 |
+
|
| 55 |
+
from google.cloud.resourcemanager_v3.services.folders import pagers
|
| 56 |
+
from google.cloud.resourcemanager_v3.types import folders
|
| 57 |
+
|
| 58 |
+
from .client import FoldersClient
|
| 59 |
+
from .transports.base import DEFAULT_CLIENT_INFO, FoldersTransport
|
| 60 |
+
from .transports.grpc_asyncio import FoldersGrpcAsyncIOTransport
|
| 61 |
+
|
| 62 |
+
try:
|
| 63 |
+
from google.api_core import client_logging # type: ignore
|
| 64 |
+
|
| 65 |
+
CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
|
| 66 |
+
except ImportError: # pragma: NO COVER
|
| 67 |
+
CLIENT_LOGGING_SUPPORTED = False
|
| 68 |
+
|
| 69 |
+
_LOGGER = std_logging.getLogger(__name__)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class FoldersAsyncClient:
|
| 73 |
+
"""Manages Cloud Platform folder resources.
|
| 74 |
+
Folders can be used to organize the resources under an
|
| 75 |
+
organization and to control the policies applied to groups of
|
| 76 |
+
resources.
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
_client: FoldersClient
|
| 80 |
+
|
| 81 |
+
# Copy defaults from the synchronous client for use here.
|
| 82 |
+
# Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
|
| 83 |
+
DEFAULT_ENDPOINT = FoldersClient.DEFAULT_ENDPOINT
|
| 84 |
+
DEFAULT_MTLS_ENDPOINT = FoldersClient.DEFAULT_MTLS_ENDPOINT
|
| 85 |
+
_DEFAULT_ENDPOINT_TEMPLATE = FoldersClient._DEFAULT_ENDPOINT_TEMPLATE
|
| 86 |
+
_DEFAULT_UNIVERSE = FoldersClient._DEFAULT_UNIVERSE
|
| 87 |
+
|
| 88 |
+
folder_path = staticmethod(FoldersClient.folder_path)
|
| 89 |
+
parse_folder_path = staticmethod(FoldersClient.parse_folder_path)
|
| 90 |
+
common_billing_account_path = staticmethod(
|
| 91 |
+
FoldersClient.common_billing_account_path
|
| 92 |
+
)
|
| 93 |
+
parse_common_billing_account_path = staticmethod(
|
| 94 |
+
FoldersClient.parse_common_billing_account_path
|
| 95 |
+
)
|
| 96 |
+
common_folder_path = staticmethod(FoldersClient.common_folder_path)
|
| 97 |
+
parse_common_folder_path = staticmethod(FoldersClient.parse_common_folder_path)
|
| 98 |
+
common_organization_path = staticmethod(FoldersClient.common_organization_path)
|
| 99 |
+
parse_common_organization_path = staticmethod(
|
| 100 |
+
FoldersClient.parse_common_organization_path
|
| 101 |
+
)
|
| 102 |
+
common_project_path = staticmethod(FoldersClient.common_project_path)
|
| 103 |
+
parse_common_project_path = staticmethod(FoldersClient.parse_common_project_path)
|
| 104 |
+
common_location_path = staticmethod(FoldersClient.common_location_path)
|
| 105 |
+
parse_common_location_path = staticmethod(FoldersClient.parse_common_location_path)
|
| 106 |
+
|
| 107 |
+
@classmethod
|
| 108 |
+
def from_service_account_info(cls, info: dict, *args, **kwargs):
|
| 109 |
+
"""Creates an instance of this client using the provided credentials
|
| 110 |
+
info.
|
| 111 |
+
|
| 112 |
+
Args:
|
| 113 |
+
info (dict): The service account private key info.
|
| 114 |
+
args: Additional arguments to pass to the constructor.
|
| 115 |
+
kwargs: Additional arguments to pass to the constructor.
|
| 116 |
+
|
| 117 |
+
Returns:
|
| 118 |
+
FoldersAsyncClient: The constructed client.
|
| 119 |
+
"""
|
| 120 |
+
sa_info_func = (
|
| 121 |
+
FoldersClient.from_service_account_info.__func__ # type: ignore
|
| 122 |
+
)
|
| 123 |
+
return sa_info_func(FoldersAsyncClient, info, *args, **kwargs)
|
| 124 |
+
|
| 125 |
+
@classmethod
|
| 126 |
+
def from_service_account_file(cls, filename: str, *args, **kwargs):
|
| 127 |
+
"""Creates an instance of this client using the provided credentials
|
| 128 |
+
file.
|
| 129 |
+
|
| 130 |
+
Args:
|
| 131 |
+
filename (str): The path to the service account private key json
|
| 132 |
+
file.
|
| 133 |
+
args: Additional arguments to pass to the constructor.
|
| 134 |
+
kwargs: Additional arguments to pass to the constructor.
|
| 135 |
+
|
| 136 |
+
Returns:
|
| 137 |
+
FoldersAsyncClient: The constructed client.
|
| 138 |
+
"""
|
| 139 |
+
sa_file_func = (
|
| 140 |
+
FoldersClient.from_service_account_file.__func__ # type: ignore
|
| 141 |
+
)
|
| 142 |
+
return sa_file_func(FoldersAsyncClient, filename, *args, **kwargs)
|
| 143 |
+
|
| 144 |
+
from_service_account_json = from_service_account_file
|
| 145 |
+
|
| 146 |
+
@classmethod
|
| 147 |
+
def get_mtls_endpoint_and_cert_source(
|
| 148 |
+
cls, client_options: Optional[ClientOptions] = None
|
| 149 |
+
):
|
| 150 |
+
"""Return the API endpoint and client cert source for mutual TLS.
|
| 151 |
+
|
| 152 |
+
The client cert source is determined in the following order:
|
| 153 |
+
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
|
| 154 |
+
client cert source is None.
|
| 155 |
+
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
|
| 156 |
+
default client cert source exists, use the default one; otherwise the client cert
|
| 157 |
+
source is None.
|
| 158 |
+
|
| 159 |
+
The API endpoint is determined in the following order:
|
| 160 |
+
(1) if `client_options.api_endpoint` if provided, use the provided one.
|
| 161 |
+
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
|
| 162 |
+
default mTLS endpoint; if the environment variable is "never", use the default API
|
| 163 |
+
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
|
| 164 |
+
use the default API endpoint.
|
| 165 |
+
|
| 166 |
+
More details can be found at https://google.aip.dev/auth/4114.
|
| 167 |
+
|
| 168 |
+
Args:
|
| 169 |
+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
|
| 170 |
+
client. Only the `api_endpoint` and `client_cert_source` properties may be used
|
| 171 |
+
in this method.
|
| 172 |
+
|
| 173 |
+
Returns:
|
| 174 |
+
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
|
| 175 |
+
client cert source to use.
|
| 176 |
+
|
| 177 |
+
Raises:
|
| 178 |
+
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
|
| 179 |
+
"""
|
| 180 |
+
return FoldersClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
|
| 181 |
+
|
| 182 |
+
@property
|
| 183 |
+
def transport(self) -> FoldersTransport:
|
| 184 |
+
"""Returns the transport used by the client instance.
|
| 185 |
+
|
| 186 |
+
Returns:
|
| 187 |
+
FoldersTransport: The transport used by the client instance.
|
| 188 |
+
"""
|
| 189 |
+
return self._client.transport
|
| 190 |
+
|
| 191 |
+
@property
|
| 192 |
+
def api_endpoint(self) -> str:
|
| 193 |
+
"""Return the API endpoint used by the client instance.
|
| 194 |
+
|
| 195 |
+
Returns:
|
| 196 |
+
str: The API endpoint used by the client instance.
|
| 197 |
+
"""
|
| 198 |
+
return self._client._api_endpoint
|
| 199 |
+
|
| 200 |
+
@property
|
| 201 |
+
def universe_domain(self) -> str:
|
| 202 |
+
"""Return the universe domain used by the client instance.
|
| 203 |
+
|
| 204 |
+
Returns:
|
| 205 |
+
str: The universe domain used
|
| 206 |
+
by the client instance.
|
| 207 |
+
"""
|
| 208 |
+
return self._client._universe_domain
|
| 209 |
+
|
| 210 |
+
get_transport_class = FoldersClient.get_transport_class
|
| 211 |
+
|
| 212 |
+
def __init__(
|
| 213 |
+
self,
|
| 214 |
+
*,
|
| 215 |
+
credentials: Optional[ga_credentials.Credentials] = None,
|
| 216 |
+
transport: Optional[
|
| 217 |
+
Union[str, FoldersTransport, Callable[..., FoldersTransport]]
|
| 218 |
+
] = "grpc_asyncio",
|
| 219 |
+
client_options: Optional[ClientOptions] = None,
|
| 220 |
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
| 221 |
+
) -> None:
|
| 222 |
+
"""Instantiates the folders async client.
|
| 223 |
+
|
| 224 |
+
Args:
|
| 225 |
+
credentials (Optional[google.auth.credentials.Credentials]): The
|
| 226 |
+
authorization credentials to attach to requests. These
|
| 227 |
+
credentials identify the application to the service; if none
|
| 228 |
+
are specified, the client will attempt to ascertain the
|
| 229 |
+
credentials from the environment.
|
| 230 |
+
transport (Optional[Union[str,FoldersTransport,Callable[..., FoldersTransport]]]):
|
| 231 |
+
The transport to use, or a Callable that constructs and returns a new transport to use.
|
| 232 |
+
If a Callable is given, it will be called with the same set of initialization
|
| 233 |
+
arguments as used in the FoldersTransport constructor.
|
| 234 |
+
If set to None, a transport is chosen automatically.
|
| 235 |
+
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
|
| 236 |
+
Custom options for the client.
|
| 237 |
+
|
| 238 |
+
1. The ``api_endpoint`` property can be used to override the
|
| 239 |
+
default endpoint provided by the client when ``transport`` is
|
| 240 |
+
not explicitly provided. Only if this property is not set and
|
| 241 |
+
``transport`` was not explicitly provided, the endpoint is
|
| 242 |
+
determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
|
| 243 |
+
variable, which have one of the following values:
|
| 244 |
+
"always" (always use the default mTLS endpoint), "never" (always
|
| 245 |
+
use the default regular endpoint) and "auto" (auto-switch to the
|
| 246 |
+
default mTLS endpoint if client certificate is present; this is
|
| 247 |
+
the default value).
|
| 248 |
+
|
| 249 |
+
2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
|
| 250 |
+
is "true", then the ``client_cert_source`` property can be used
|
| 251 |
+
to provide a client certificate for mTLS transport. If
|
| 252 |
+
not provided, the default SSL client certificate will be used if
|
| 253 |
+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
|
| 254 |
+
set, no client certificate will be used.
|
| 255 |
+
|
| 256 |
+
3. The ``universe_domain`` property can be used to override the
|
| 257 |
+
default "googleapis.com" universe. Note that ``api_endpoint``
|
| 258 |
+
property still takes precedence; and ``universe_domain`` is
|
| 259 |
+
currently not supported for mTLS.
|
| 260 |
+
|
| 261 |
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
| 262 |
+
The client info used to send a user-agent string along with
|
| 263 |
+
API requests. If ``None``, then default info will be used.
|
| 264 |
+
Generally, you only need to set this if you're developing
|
| 265 |
+
your own client library.
|
| 266 |
+
|
| 267 |
+
Raises:
|
| 268 |
+
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
|
| 269 |
+
creation failed for any reason.
|
| 270 |
+
"""
|
| 271 |
+
self._client = FoldersClient(
|
| 272 |
+
credentials=credentials,
|
| 273 |
+
transport=transport,
|
| 274 |
+
client_options=client_options,
|
| 275 |
+
client_info=client_info,
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
|
| 279 |
+
std_logging.DEBUG
|
| 280 |
+
): # pragma: NO COVER
|
| 281 |
+
_LOGGER.debug(
|
| 282 |
+
"Created client `google.cloud.resourcemanager_v3.FoldersAsyncClient`.",
|
| 283 |
+
extra={
|
| 284 |
+
"serviceName": "google.cloud.resourcemanager.v3.Folders",
|
| 285 |
+
"universeDomain": getattr(
|
| 286 |
+
self._client._transport._credentials, "universe_domain", ""
|
| 287 |
+
),
|
| 288 |
+
"credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}",
|
| 289 |
+
"credentialsInfo": getattr(
|
| 290 |
+
self.transport._credentials, "get_cred_info", lambda: None
|
| 291 |
+
)(),
|
| 292 |
+
}
|
| 293 |
+
if hasattr(self._client._transport, "_credentials")
|
| 294 |
+
else {
|
| 295 |
+
"serviceName": "google.cloud.resourcemanager.v3.Folders",
|
| 296 |
+
"credentialsType": None,
|
| 297 |
+
},
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
async def get_folder(
|
| 301 |
+
self,
|
| 302 |
+
request: Optional[Union[folders.GetFolderRequest, dict]] = None,
|
| 303 |
+
*,
|
| 304 |
+
name: Optional[str] = None,
|
| 305 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 306 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 307 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 308 |
+
) -> folders.Folder:
|
| 309 |
+
r"""Retrieves a folder identified by the supplied resource name.
|
| 310 |
+
Valid folder resource names have the format
|
| 311 |
+
``folders/{folder_id}`` (for example, ``folders/1234``). The
|
| 312 |
+
caller must have ``resourcemanager.folders.get`` permission on
|
| 313 |
+
the identified folder.
|
| 314 |
+
|
| 315 |
+
.. code-block:: python
|
| 316 |
+
|
| 317 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 318 |
+
# code template only.
|
| 319 |
+
# It will require modifications to work:
|
| 320 |
+
# - It may require correct/in-range values for request initialization.
|
| 321 |
+
# - It may require specifying regional endpoints when creating the service
|
| 322 |
+
# client as shown in:
|
| 323 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 324 |
+
from google.cloud import resourcemanager_v3
|
| 325 |
+
|
| 326 |
+
async def sample_get_folder():
|
| 327 |
+
# Create a client
|
| 328 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 329 |
+
|
| 330 |
+
# Initialize request argument(s)
|
| 331 |
+
request = resourcemanager_v3.GetFolderRequest(
|
| 332 |
+
name="name_value",
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
# Make the request
|
| 336 |
+
response = await client.get_folder(request=request)
|
| 337 |
+
|
| 338 |
+
# Handle the response
|
| 339 |
+
print(response)
|
| 340 |
+
|
| 341 |
+
Args:
|
| 342 |
+
request (Optional[Union[google.cloud.resourcemanager_v3.types.GetFolderRequest, dict]]):
|
| 343 |
+
The request object. The GetFolder request message.
|
| 344 |
+
name (:class:`str`):
|
| 345 |
+
Required. The resource name of the folder to retrieve.
|
| 346 |
+
Must be of the form ``folders/{folder_id}``.
|
| 347 |
+
|
| 348 |
+
This corresponds to the ``name`` field
|
| 349 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 350 |
+
should not be set.
|
| 351 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 352 |
+
should be retried.
|
| 353 |
+
timeout (float): The timeout for this request.
|
| 354 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 355 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 356 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 357 |
+
be of type `bytes`.
|
| 358 |
+
|
| 359 |
+
Returns:
|
| 360 |
+
google.cloud.resourcemanager_v3.types.Folder:
|
| 361 |
+
A folder in an organization's
|
| 362 |
+
resource hierarchy, used to organize
|
| 363 |
+
that organization's resources.
|
| 364 |
+
|
| 365 |
+
"""
|
| 366 |
+
# Create or coerce a protobuf request object.
|
| 367 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 368 |
+
# gotten any keyword arguments that map to the request.
|
| 369 |
+
flattened_params = [name]
|
| 370 |
+
has_flattened_params = (
|
| 371 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 372 |
+
)
|
| 373 |
+
if request is not None and has_flattened_params:
|
| 374 |
+
raise ValueError(
|
| 375 |
+
"If the `request` argument is set, then none of "
|
| 376 |
+
"the individual field arguments should be set."
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
# - Use the request object if provided (there's no risk of modifying the input as
|
| 380 |
+
# there are no flattened fields), or create one.
|
| 381 |
+
if not isinstance(request, folders.GetFolderRequest):
|
| 382 |
+
request = folders.GetFolderRequest(request)
|
| 383 |
+
|
| 384 |
+
# If we have keyword arguments corresponding to fields on the
|
| 385 |
+
# request, apply these.
|
| 386 |
+
if name is not None:
|
| 387 |
+
request.name = name
|
| 388 |
+
|
| 389 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 390 |
+
# and friendly error handling.
|
| 391 |
+
rpc = self._client._transport._wrapped_methods[
|
| 392 |
+
self._client._transport.get_folder
|
| 393 |
+
]
|
| 394 |
+
|
| 395 |
+
# Certain fields should be provided within the metadata header;
|
| 396 |
+
# add these here.
|
| 397 |
+
metadata = tuple(metadata) + (
|
| 398 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
# Validate the universe domain.
|
| 402 |
+
self._client._validate_universe_domain()
|
| 403 |
+
|
| 404 |
+
# Send the request.
|
| 405 |
+
response = await rpc(
|
| 406 |
+
request,
|
| 407 |
+
retry=retry,
|
| 408 |
+
timeout=timeout,
|
| 409 |
+
metadata=metadata,
|
| 410 |
+
)
|
| 411 |
+
|
| 412 |
+
# Done; return the response.
|
| 413 |
+
return response
|
| 414 |
+
|
| 415 |
+
async def list_folders(
|
| 416 |
+
self,
|
| 417 |
+
request: Optional[Union[folders.ListFoldersRequest, dict]] = None,
|
| 418 |
+
*,
|
| 419 |
+
parent: Optional[str] = None,
|
| 420 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 421 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 422 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 423 |
+
) -> pagers.ListFoldersAsyncPager:
|
| 424 |
+
r"""Lists the folders that are direct descendants of supplied parent
|
| 425 |
+
resource. ``list()`` provides a strongly consistent view of the
|
| 426 |
+
folders underneath the specified parent resource. ``list()``
|
| 427 |
+
returns folders sorted based upon the (ascending) lexical
|
| 428 |
+
ordering of their display_name. The caller must have
|
| 429 |
+
``resourcemanager.folders.list`` permission on the identified
|
| 430 |
+
parent.
|
| 431 |
+
|
| 432 |
+
.. code-block:: python
|
| 433 |
+
|
| 434 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 435 |
+
# code template only.
|
| 436 |
+
# It will require modifications to work:
|
| 437 |
+
# - It may require correct/in-range values for request initialization.
|
| 438 |
+
# - It may require specifying regional endpoints when creating the service
|
| 439 |
+
# client as shown in:
|
| 440 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 441 |
+
from google.cloud import resourcemanager_v3
|
| 442 |
+
|
| 443 |
+
async def sample_list_folders():
|
| 444 |
+
# Create a client
|
| 445 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 446 |
+
|
| 447 |
+
# Initialize request argument(s)
|
| 448 |
+
request = resourcemanager_v3.ListFoldersRequest(
|
| 449 |
+
parent="parent_value",
|
| 450 |
+
)
|
| 451 |
+
|
| 452 |
+
# Make the request
|
| 453 |
+
page_result = client.list_folders(request=request)
|
| 454 |
+
|
| 455 |
+
# Handle the response
|
| 456 |
+
async for response in page_result:
|
| 457 |
+
print(response)
|
| 458 |
+
|
| 459 |
+
Args:
|
| 460 |
+
request (Optional[Union[google.cloud.resourcemanager_v3.types.ListFoldersRequest, dict]]):
|
| 461 |
+
The request object. The ListFolders request message.
|
| 462 |
+
parent (:class:`str`):
|
| 463 |
+
Required. The name of the parent resource whose folders
|
| 464 |
+
are being listed. Only children of this parent resource
|
| 465 |
+
are listed; descendants are not listed.
|
| 466 |
+
|
| 467 |
+
If the parent is a folder, use the value
|
| 468 |
+
``folders/{folder_id}``. If the parent is an
|
| 469 |
+
organization, use the value ``organizations/{org_id}``.
|
| 470 |
+
|
| 471 |
+
Access to this method is controlled by checking the
|
| 472 |
+
``resourcemanager.folders.list`` permission on the
|
| 473 |
+
``parent``.
|
| 474 |
+
|
| 475 |
+
This corresponds to the ``parent`` field
|
| 476 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 477 |
+
should not be set.
|
| 478 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 479 |
+
should be retried.
|
| 480 |
+
timeout (float): The timeout for this request.
|
| 481 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 482 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 483 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 484 |
+
be of type `bytes`.
|
| 485 |
+
|
| 486 |
+
Returns:
|
| 487 |
+
google.cloud.resourcemanager_v3.services.folders.pagers.ListFoldersAsyncPager:
|
| 488 |
+
The ListFolders response message.
|
| 489 |
+
|
| 490 |
+
Iterating over this object will yield
|
| 491 |
+
results and resolve additional pages
|
| 492 |
+
automatically.
|
| 493 |
+
|
| 494 |
+
"""
|
| 495 |
+
# Create or coerce a protobuf request object.
|
| 496 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 497 |
+
# gotten any keyword arguments that map to the request.
|
| 498 |
+
flattened_params = [parent]
|
| 499 |
+
has_flattened_params = (
|
| 500 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 501 |
+
)
|
| 502 |
+
if request is not None and has_flattened_params:
|
| 503 |
+
raise ValueError(
|
| 504 |
+
"If the `request` argument is set, then none of "
|
| 505 |
+
"the individual field arguments should be set."
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
# - Use the request object if provided (there's no risk of modifying the input as
|
| 509 |
+
# there are no flattened fields), or create one.
|
| 510 |
+
if not isinstance(request, folders.ListFoldersRequest):
|
| 511 |
+
request = folders.ListFoldersRequest(request)
|
| 512 |
+
|
| 513 |
+
# If we have keyword arguments corresponding to fields on the
|
| 514 |
+
# request, apply these.
|
| 515 |
+
if parent is not None:
|
| 516 |
+
request.parent = parent
|
| 517 |
+
|
| 518 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 519 |
+
# and friendly error handling.
|
| 520 |
+
rpc = self._client._transport._wrapped_methods[
|
| 521 |
+
self._client._transport.list_folders
|
| 522 |
+
]
|
| 523 |
+
|
| 524 |
+
# Validate the universe domain.
|
| 525 |
+
self._client._validate_universe_domain()
|
| 526 |
+
|
| 527 |
+
# Send the request.
|
| 528 |
+
response = await rpc(
|
| 529 |
+
request,
|
| 530 |
+
retry=retry,
|
| 531 |
+
timeout=timeout,
|
| 532 |
+
metadata=metadata,
|
| 533 |
+
)
|
| 534 |
+
|
| 535 |
+
# This method is paged; wrap the response in a pager, which provides
|
| 536 |
+
# an `__aiter__` convenience method.
|
| 537 |
+
response = pagers.ListFoldersAsyncPager(
|
| 538 |
+
method=rpc,
|
| 539 |
+
request=request,
|
| 540 |
+
response=response,
|
| 541 |
+
retry=retry,
|
| 542 |
+
timeout=timeout,
|
| 543 |
+
metadata=metadata,
|
| 544 |
+
)
|
| 545 |
+
|
| 546 |
+
# Done; return the response.
|
| 547 |
+
return response
|
| 548 |
+
|
| 549 |
+
async def search_folders(
|
| 550 |
+
self,
|
| 551 |
+
request: Optional[Union[folders.SearchFoldersRequest, dict]] = None,
|
| 552 |
+
*,
|
| 553 |
+
query: Optional[str] = None,
|
| 554 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 555 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 556 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 557 |
+
) -> pagers.SearchFoldersAsyncPager:
|
| 558 |
+
r"""Search for folders that match specific filter criteria.
|
| 559 |
+
``search()`` provides an eventually consistent view of the
|
| 560 |
+
folders a user has access to which meet the specified filter
|
| 561 |
+
criteria.
|
| 562 |
+
|
| 563 |
+
This will only return folders on which the caller has the
|
| 564 |
+
permission ``resourcemanager.folders.get``.
|
| 565 |
+
|
| 566 |
+
.. code-block:: python
|
| 567 |
+
|
| 568 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 569 |
+
# code template only.
|
| 570 |
+
# It will require modifications to work:
|
| 571 |
+
# - It may require correct/in-range values for request initialization.
|
| 572 |
+
# - It may require specifying regional endpoints when creating the service
|
| 573 |
+
# client as shown in:
|
| 574 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 575 |
+
from google.cloud import resourcemanager_v3
|
| 576 |
+
|
| 577 |
+
async def sample_search_folders():
|
| 578 |
+
# Create a client
|
| 579 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 580 |
+
|
| 581 |
+
# Initialize request argument(s)
|
| 582 |
+
request = resourcemanager_v3.SearchFoldersRequest(
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
# Make the request
|
| 586 |
+
page_result = client.search_folders(request=request)
|
| 587 |
+
|
| 588 |
+
# Handle the response
|
| 589 |
+
async for response in page_result:
|
| 590 |
+
print(response)
|
| 591 |
+
|
| 592 |
+
Args:
|
| 593 |
+
request (Optional[Union[google.cloud.resourcemanager_v3.types.SearchFoldersRequest, dict]]):
|
| 594 |
+
The request object. The request message for searching
|
| 595 |
+
folders.
|
| 596 |
+
query (:class:`str`):
|
| 597 |
+
Optional. Search criteria used to select the folders to
|
| 598 |
+
return. If no search criteria is specified then all
|
| 599 |
+
accessible folders will be returned.
|
| 600 |
+
|
| 601 |
+
Query expressions can be used to restrict results based
|
| 602 |
+
upon displayName, state and parent, where the operators
|
| 603 |
+
``=`` (``:``) ``NOT``, ``AND`` and ``OR`` can be used
|
| 604 |
+
along with the suffix wildcard symbol ``*``.
|
| 605 |
+
|
| 606 |
+
The ``displayName`` field in a query expression should
|
| 607 |
+
use escaped quotes for values that include whitespace to
|
| 608 |
+
prevent unexpected behavior.
|
| 609 |
+
|
| 610 |
+
::
|
| 611 |
+
|
| 612 |
+
| Field | Description |
|
| 613 |
+
|-------------------------|----------------------------------------|
|
| 614 |
+
| displayName | Filters by displayName. |
|
| 615 |
+
| parent | Filters by parent (for example: folders/123). |
|
| 616 |
+
| state, lifecycleState | Filters by state. |
|
| 617 |
+
|
| 618 |
+
Some example queries are:
|
| 619 |
+
|
| 620 |
+
- Query ``displayName=Test*`` returns Folder resources
|
| 621 |
+
whose display name starts with "Test".
|
| 622 |
+
- Query ``state=ACTIVE`` returns Folder resources with
|
| 623 |
+
``state`` set to ``ACTIVE``.
|
| 624 |
+
- Query ``parent=folders/123`` returns Folder resources
|
| 625 |
+
that have ``folders/123`` as a parent resource.
|
| 626 |
+
- Query ``parent=folders/123 AND state=ACTIVE`` returns
|
| 627 |
+
active Folder resources that have ``folders/123`` as a
|
| 628 |
+
parent resource.
|
| 629 |
+
- Query ``displayName=\\"Test String\\"`` returns Folder
|
| 630 |
+
resources with display names that include both "Test"
|
| 631 |
+
and "String".
|
| 632 |
+
|
| 633 |
+
This corresponds to the ``query`` field
|
| 634 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 635 |
+
should not be set.
|
| 636 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 637 |
+
should be retried.
|
| 638 |
+
timeout (float): The timeout for this request.
|
| 639 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 640 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 641 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 642 |
+
be of type `bytes`.
|
| 643 |
+
|
| 644 |
+
Returns:
|
| 645 |
+
google.cloud.resourcemanager_v3.services.folders.pagers.SearchFoldersAsyncPager:
|
| 646 |
+
The response message for searching
|
| 647 |
+
folders.
|
| 648 |
+
Iterating over this object will yield
|
| 649 |
+
results and resolve additional pages
|
| 650 |
+
automatically.
|
| 651 |
+
|
| 652 |
+
"""
|
| 653 |
+
# Create or coerce a protobuf request object.
|
| 654 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 655 |
+
# gotten any keyword arguments that map to the request.
|
| 656 |
+
flattened_params = [query]
|
| 657 |
+
has_flattened_params = (
|
| 658 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 659 |
+
)
|
| 660 |
+
if request is not None and has_flattened_params:
|
| 661 |
+
raise ValueError(
|
| 662 |
+
"If the `request` argument is set, then none of "
|
| 663 |
+
"the individual field arguments should be set."
|
| 664 |
+
)
|
| 665 |
+
|
| 666 |
+
# - Use the request object if provided (there's no risk of modifying the input as
|
| 667 |
+
# there are no flattened fields), or create one.
|
| 668 |
+
if not isinstance(request, folders.SearchFoldersRequest):
|
| 669 |
+
request = folders.SearchFoldersRequest(request)
|
| 670 |
+
|
| 671 |
+
# If we have keyword arguments corresponding to fields on the
|
| 672 |
+
# request, apply these.
|
| 673 |
+
if query is not None:
|
| 674 |
+
request.query = query
|
| 675 |
+
|
| 676 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 677 |
+
# and friendly error handling.
|
| 678 |
+
rpc = self._client._transport._wrapped_methods[
|
| 679 |
+
self._client._transport.search_folders
|
| 680 |
+
]
|
| 681 |
+
|
| 682 |
+
# Validate the universe domain.
|
| 683 |
+
self._client._validate_universe_domain()
|
| 684 |
+
|
| 685 |
+
# Send the request.
|
| 686 |
+
response = await rpc(
|
| 687 |
+
request,
|
| 688 |
+
retry=retry,
|
| 689 |
+
timeout=timeout,
|
| 690 |
+
metadata=metadata,
|
| 691 |
+
)
|
| 692 |
+
|
| 693 |
+
# This method is paged; wrap the response in a pager, which provides
|
| 694 |
+
# an `__aiter__` convenience method.
|
| 695 |
+
response = pagers.SearchFoldersAsyncPager(
|
| 696 |
+
method=rpc,
|
| 697 |
+
request=request,
|
| 698 |
+
response=response,
|
| 699 |
+
retry=retry,
|
| 700 |
+
timeout=timeout,
|
| 701 |
+
metadata=metadata,
|
| 702 |
+
)
|
| 703 |
+
|
| 704 |
+
# Done; return the response.
|
| 705 |
+
return response
|
| 706 |
+
|
| 707 |
+
async def create_folder(
|
| 708 |
+
self,
|
| 709 |
+
request: Optional[Union[folders.CreateFolderRequest, dict]] = None,
|
| 710 |
+
*,
|
| 711 |
+
folder: Optional[folders.Folder] = None,
|
| 712 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 713 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 714 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 715 |
+
) -> operation_async.AsyncOperation:
|
| 716 |
+
r"""Creates a folder in the resource hierarchy. Returns an
|
| 717 |
+
``Operation`` which can be used to track the progress of the
|
| 718 |
+
folder creation workflow. Upon success, the
|
| 719 |
+
``Operation.response`` field will be populated with the created
|
| 720 |
+
Folder.
|
| 721 |
+
|
| 722 |
+
In order to succeed, the addition of this new folder must not
|
| 723 |
+
violate the folder naming, height, or fanout constraints.
|
| 724 |
+
|
| 725 |
+
- The folder's ``display_name`` must be distinct from all other
|
| 726 |
+
folders that share its parent.
|
| 727 |
+
- The addition of the folder must not cause the active folder
|
| 728 |
+
hierarchy to exceed a height of 10. Note, the full active +
|
| 729 |
+
deleted folder hierarchy is allowed to reach a height of 20;
|
| 730 |
+
this provides additional headroom when moving folders that
|
| 731 |
+
contain deleted folders.
|
| 732 |
+
- The addition of the folder must not cause the total number of
|
| 733 |
+
folders under its parent to exceed 300.
|
| 734 |
+
|
| 735 |
+
If the operation fails due to a folder constraint violation,
|
| 736 |
+
some errors may be returned by the ``CreateFolder`` request,
|
| 737 |
+
with status code ``FAILED_PRECONDITION`` and an error
|
| 738 |
+
description. Other folder constraint violations will be
|
| 739 |
+
communicated in the ``Operation``, with the specific
|
| 740 |
+
``PreconditionFailure`` returned in the details list in the
|
| 741 |
+
``Operation.error`` field.
|
| 742 |
+
|
| 743 |
+
The caller must have ``resourcemanager.folders.create``
|
| 744 |
+
permission on the identified parent.
|
| 745 |
+
|
| 746 |
+
.. code-block:: python
|
| 747 |
+
|
| 748 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 749 |
+
# code template only.
|
| 750 |
+
# It will require modifications to work:
|
| 751 |
+
# - It may require correct/in-range values for request initialization.
|
| 752 |
+
# - It may require specifying regional endpoints when creating the service
|
| 753 |
+
# client as shown in:
|
| 754 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 755 |
+
from google.cloud import resourcemanager_v3
|
| 756 |
+
|
| 757 |
+
async def sample_create_folder():
|
| 758 |
+
# Create a client
|
| 759 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 760 |
+
|
| 761 |
+
# Initialize request argument(s)
|
| 762 |
+
folder = resourcemanager_v3.Folder()
|
| 763 |
+
folder.parent = "parent_value"
|
| 764 |
+
|
| 765 |
+
request = resourcemanager_v3.CreateFolderRequest(
|
| 766 |
+
folder=folder,
|
| 767 |
+
)
|
| 768 |
+
|
| 769 |
+
# Make the request
|
| 770 |
+
operation = client.create_folder(request=request)
|
| 771 |
+
|
| 772 |
+
print("Waiting for operation to complete...")
|
| 773 |
+
|
| 774 |
+
response = (await operation).result()
|
| 775 |
+
|
| 776 |
+
# Handle the response
|
| 777 |
+
print(response)
|
| 778 |
+
|
| 779 |
+
Args:
|
| 780 |
+
request (Optional[Union[google.cloud.resourcemanager_v3.types.CreateFolderRequest, dict]]):
|
| 781 |
+
The request object. The CreateFolder request message.
|
| 782 |
+
folder (:class:`google.cloud.resourcemanager_v3.types.Folder`):
|
| 783 |
+
Required. The folder being created,
|
| 784 |
+
only the display name and parent will be
|
| 785 |
+
consulted. All other fields will be
|
| 786 |
+
ignored.
|
| 787 |
+
|
| 788 |
+
This corresponds to the ``folder`` field
|
| 789 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 790 |
+
should not be set.
|
| 791 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 792 |
+
should be retried.
|
| 793 |
+
timeout (float): The timeout for this request.
|
| 794 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 795 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 796 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 797 |
+
be of type `bytes`.
|
| 798 |
+
|
| 799 |
+
Returns:
|
| 800 |
+
google.api_core.operation_async.AsyncOperation:
|
| 801 |
+
An object representing a long-running operation.
|
| 802 |
+
|
| 803 |
+
The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Folder` A folder in an organization's resource hierarchy, used to
|
| 804 |
+
organize that organization's resources.
|
| 805 |
+
|
| 806 |
+
"""
|
| 807 |
+
# Create or coerce a protobuf request object.
|
| 808 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 809 |
+
# gotten any keyword arguments that map to the request.
|
| 810 |
+
flattened_params = [folder]
|
| 811 |
+
has_flattened_params = (
|
| 812 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 813 |
+
)
|
| 814 |
+
if request is not None and has_flattened_params:
|
| 815 |
+
raise ValueError(
|
| 816 |
+
"If the `request` argument is set, then none of "
|
| 817 |
+
"the individual field arguments should be set."
|
| 818 |
+
)
|
| 819 |
+
|
| 820 |
+
# - Use the request object if provided (there's no risk of modifying the input as
|
| 821 |
+
# there are no flattened fields), or create one.
|
| 822 |
+
if not isinstance(request, folders.CreateFolderRequest):
|
| 823 |
+
request = folders.CreateFolderRequest(request)
|
| 824 |
+
|
| 825 |
+
# If we have keyword arguments corresponding to fields on the
|
| 826 |
+
# request, apply these.
|
| 827 |
+
if folder is not None:
|
| 828 |
+
request.folder = folder
|
| 829 |
+
|
| 830 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 831 |
+
# and friendly error handling.
|
| 832 |
+
rpc = self._client._transport._wrapped_methods[
|
| 833 |
+
self._client._transport.create_folder
|
| 834 |
+
]
|
| 835 |
+
|
| 836 |
+
# Validate the universe domain.
|
| 837 |
+
self._client._validate_universe_domain()
|
| 838 |
+
|
| 839 |
+
# Send the request.
|
| 840 |
+
response = await rpc(
|
| 841 |
+
request,
|
| 842 |
+
retry=retry,
|
| 843 |
+
timeout=timeout,
|
| 844 |
+
metadata=metadata,
|
| 845 |
+
)
|
| 846 |
+
|
| 847 |
+
# Wrap the response in an operation future.
|
| 848 |
+
response = operation_async.from_gapic(
|
| 849 |
+
response,
|
| 850 |
+
self._client._transport.operations_client,
|
| 851 |
+
folders.Folder,
|
| 852 |
+
metadata_type=folders.CreateFolderMetadata,
|
| 853 |
+
)
|
| 854 |
+
|
| 855 |
+
# Done; return the response.
|
| 856 |
+
return response
|
| 857 |
+
|
| 858 |
+
async def update_folder(
|
| 859 |
+
self,
|
| 860 |
+
request: Optional[Union[folders.UpdateFolderRequest, dict]] = None,
|
| 861 |
+
*,
|
| 862 |
+
folder: Optional[folders.Folder] = None,
|
| 863 |
+
update_mask: Optional[field_mask_pb2.FieldMask] = None,
|
| 864 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 865 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 866 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 867 |
+
) -> operation_async.AsyncOperation:
|
| 868 |
+
r"""Updates a folder, changing its ``display_name``. Changes to the
|
| 869 |
+
folder ``display_name`` will be rejected if they violate either
|
| 870 |
+
the ``display_name`` formatting rules or the naming constraints
|
| 871 |
+
described in the
|
| 872 |
+
[CreateFolder][google.cloud.resourcemanager.v3.Folders.CreateFolder]
|
| 873 |
+
documentation.
|
| 874 |
+
|
| 875 |
+
The folder's ``display_name`` must start and end with a letter
|
| 876 |
+
or digit, may contain letters, digits, spaces, hyphens and
|
| 877 |
+
underscores and can be between 3 and 30 characters. This is
|
| 878 |
+
captured by the regular expression:
|
| 879 |
+
``[\p{L}\p{N}][\p{L}\p{N}_- ]{1,28}[\p{L}\p{N}]``. The caller
|
| 880 |
+
must have ``resourcemanager.folders.update`` permission on the
|
| 881 |
+
identified folder.
|
| 882 |
+
|
| 883 |
+
If the update fails due to the unique name constraint then a
|
| 884 |
+
``PreconditionFailure`` explaining this violation will be
|
| 885 |
+
returned in the Status.details field.
|
| 886 |
+
|
| 887 |
+
.. code-block:: python
|
| 888 |
+
|
| 889 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 890 |
+
# code template only.
|
| 891 |
+
# It will require modifications to work:
|
| 892 |
+
# - It may require correct/in-range values for request initialization.
|
| 893 |
+
# - It may require specifying regional endpoints when creating the service
|
| 894 |
+
# client as shown in:
|
| 895 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 896 |
+
from google.cloud import resourcemanager_v3
|
| 897 |
+
|
| 898 |
+
async def sample_update_folder():
|
| 899 |
+
# Create a client
|
| 900 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 901 |
+
|
| 902 |
+
# Initialize request argument(s)
|
| 903 |
+
folder = resourcemanager_v3.Folder()
|
| 904 |
+
folder.parent = "parent_value"
|
| 905 |
+
|
| 906 |
+
request = resourcemanager_v3.UpdateFolderRequest(
|
| 907 |
+
folder=folder,
|
| 908 |
+
)
|
| 909 |
+
|
| 910 |
+
# Make the request
|
| 911 |
+
operation = client.update_folder(request=request)
|
| 912 |
+
|
| 913 |
+
print("Waiting for operation to complete...")
|
| 914 |
+
|
| 915 |
+
response = (await operation).result()
|
| 916 |
+
|
| 917 |
+
# Handle the response
|
| 918 |
+
print(response)
|
| 919 |
+
|
| 920 |
+
Args:
|
| 921 |
+
request (Optional[Union[google.cloud.resourcemanager_v3.types.UpdateFolderRequest, dict]]):
|
| 922 |
+
The request object. The request sent to the
|
| 923 |
+
[UpdateFolder][google.cloud.resourcemanager.v3.Folder.UpdateFolder]
|
| 924 |
+
method.
|
| 925 |
+
|
| 926 |
+
Only the ``display_name`` field can be changed. All
|
| 927 |
+
other fields will be ignored. Use the
|
| 928 |
+
[MoveFolder][google.cloud.resourcemanager.v3.Folders.MoveFolder]
|
| 929 |
+
method to change the ``parent`` field.
|
| 930 |
+
folder (:class:`google.cloud.resourcemanager_v3.types.Folder`):
|
| 931 |
+
Required. The new definition of the Folder. It must
|
| 932 |
+
include the ``name`` field, which cannot be changed.
|
| 933 |
+
|
| 934 |
+
This corresponds to the ``folder`` field
|
| 935 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 936 |
+
should not be set.
|
| 937 |
+
update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
|
| 938 |
+
Required. Fields to be updated. Only the
|
| 939 |
+
``display_name`` can be updated.
|
| 940 |
+
|
| 941 |
+
This corresponds to the ``update_mask`` field
|
| 942 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 943 |
+
should not be set.
|
| 944 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 945 |
+
should be retried.
|
| 946 |
+
timeout (float): The timeout for this request.
|
| 947 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 948 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 949 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 950 |
+
be of type `bytes`.
|
| 951 |
+
|
| 952 |
+
Returns:
|
| 953 |
+
google.api_core.operation_async.AsyncOperation:
|
| 954 |
+
An object representing a long-running operation.
|
| 955 |
+
|
| 956 |
+
The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Folder` A folder in an organization's resource hierarchy, used to
|
| 957 |
+
organize that organization's resources.
|
| 958 |
+
|
| 959 |
+
"""
|
| 960 |
+
# Create or coerce a protobuf request object.
|
| 961 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 962 |
+
# gotten any keyword arguments that map to the request.
|
| 963 |
+
flattened_params = [folder, update_mask]
|
| 964 |
+
has_flattened_params = (
|
| 965 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 966 |
+
)
|
| 967 |
+
if request is not None and has_flattened_params:
|
| 968 |
+
raise ValueError(
|
| 969 |
+
"If the `request` argument is set, then none of "
|
| 970 |
+
"the individual field arguments should be set."
|
| 971 |
+
)
|
| 972 |
+
|
| 973 |
+
# - Use the request object if provided (there's no risk of modifying the input as
|
| 974 |
+
# there are no flattened fields), or create one.
|
| 975 |
+
if not isinstance(request, folders.UpdateFolderRequest):
|
| 976 |
+
request = folders.UpdateFolderRequest(request)
|
| 977 |
+
|
| 978 |
+
# If we have keyword arguments corresponding to fields on the
|
| 979 |
+
# request, apply these.
|
| 980 |
+
if folder is not None:
|
| 981 |
+
request.folder = folder
|
| 982 |
+
if update_mask is not None:
|
| 983 |
+
request.update_mask = update_mask
|
| 984 |
+
|
| 985 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 986 |
+
# and friendly error handling.
|
| 987 |
+
rpc = self._client._transport._wrapped_methods[
|
| 988 |
+
self._client._transport.update_folder
|
| 989 |
+
]
|
| 990 |
+
|
| 991 |
+
# Certain fields should be provided within the metadata header;
|
| 992 |
+
# add these here.
|
| 993 |
+
metadata = tuple(metadata) + (
|
| 994 |
+
gapic_v1.routing_header.to_grpc_metadata(
|
| 995 |
+
(("folder.name", request.folder.name),)
|
| 996 |
+
),
|
| 997 |
+
)
|
| 998 |
+
|
| 999 |
+
# Validate the universe domain.
|
| 1000 |
+
self._client._validate_universe_domain()
|
| 1001 |
+
|
| 1002 |
+
# Send the request.
|
| 1003 |
+
response = await rpc(
|
| 1004 |
+
request,
|
| 1005 |
+
retry=retry,
|
| 1006 |
+
timeout=timeout,
|
| 1007 |
+
metadata=metadata,
|
| 1008 |
+
)
|
| 1009 |
+
|
| 1010 |
+
# Wrap the response in an operation future.
|
| 1011 |
+
response = operation_async.from_gapic(
|
| 1012 |
+
response,
|
| 1013 |
+
self._client._transport.operations_client,
|
| 1014 |
+
folders.Folder,
|
| 1015 |
+
metadata_type=folders.UpdateFolderMetadata,
|
| 1016 |
+
)
|
| 1017 |
+
|
| 1018 |
+
# Done; return the response.
|
| 1019 |
+
return response
|
| 1020 |
+
|
| 1021 |
+
async def move_folder(
|
| 1022 |
+
self,
|
| 1023 |
+
request: Optional[Union[folders.MoveFolderRequest, dict]] = None,
|
| 1024 |
+
*,
|
| 1025 |
+
name: Optional[str] = None,
|
| 1026 |
+
destination_parent: Optional[str] = None,
|
| 1027 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 1028 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 1029 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 1030 |
+
) -> operation_async.AsyncOperation:
|
| 1031 |
+
r"""Moves a folder under a new resource parent. Returns an
|
| 1032 |
+
``Operation`` which can be used to track the progress of the
|
| 1033 |
+
folder move workflow. Upon success, the ``Operation.response``
|
| 1034 |
+
field will be populated with the moved folder. Upon failure, a
|
| 1035 |
+
``FolderOperationError`` categorizing the failure cause will be
|
| 1036 |
+
returned - if the failure occurs synchronously then the
|
| 1037 |
+
``FolderOperationError`` will be returned in the
|
| 1038 |
+
``Status.details`` field. If it occurs asynchronously, then the
|
| 1039 |
+
FolderOperation will be returned in the ``Operation.error``
|
| 1040 |
+
field. In addition, the ``Operation.metadata`` field will be
|
| 1041 |
+
populated with a ``FolderOperation`` message as an aid to
|
| 1042 |
+
stateless clients. Folder moves will be rejected if they violate
|
| 1043 |
+
either the naming, height, or fanout constraints described in
|
| 1044 |
+
the
|
| 1045 |
+
[CreateFolder][google.cloud.resourcemanager.v3.Folders.CreateFolder]
|
| 1046 |
+
documentation. The caller must have
|
| 1047 |
+
``resourcemanager.folders.move`` permission on the folder's
|
| 1048 |
+
current and proposed new parent.
|
| 1049 |
+
|
| 1050 |
+
.. code-block:: python
|
| 1051 |
+
|
| 1052 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 1053 |
+
# code template only.
|
| 1054 |
+
# It will require modifications to work:
|
| 1055 |
+
# - It may require correct/in-range values for request initialization.
|
| 1056 |
+
# - It may require specifying regional endpoints when creating the service
|
| 1057 |
+
# client as shown in:
|
| 1058 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 1059 |
+
from google.cloud import resourcemanager_v3
|
| 1060 |
+
|
| 1061 |
+
async def sample_move_folder():
|
| 1062 |
+
# Create a client
|
| 1063 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 1064 |
+
|
| 1065 |
+
# Initialize request argument(s)
|
| 1066 |
+
request = resourcemanager_v3.MoveFolderRequest(
|
| 1067 |
+
name="name_value",
|
| 1068 |
+
destination_parent="destination_parent_value",
|
| 1069 |
+
)
|
| 1070 |
+
|
| 1071 |
+
# Make the request
|
| 1072 |
+
operation = client.move_folder(request=request)
|
| 1073 |
+
|
| 1074 |
+
print("Waiting for operation to complete...")
|
| 1075 |
+
|
| 1076 |
+
response = (await operation).result()
|
| 1077 |
+
|
| 1078 |
+
# Handle the response
|
| 1079 |
+
print(response)
|
| 1080 |
+
|
| 1081 |
+
Args:
|
| 1082 |
+
request (Optional[Union[google.cloud.resourcemanager_v3.types.MoveFolderRequest, dict]]):
|
| 1083 |
+
The request object. The MoveFolder request message.
|
| 1084 |
+
name (:class:`str`):
|
| 1085 |
+
Required. The resource name of the Folder to move. Must
|
| 1086 |
+
be of the form folders/{folder_id}
|
| 1087 |
+
|
| 1088 |
+
This corresponds to the ``name`` field
|
| 1089 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 1090 |
+
should not be set.
|
| 1091 |
+
destination_parent (:class:`str`):
|
| 1092 |
+
Required. The resource name of the folder or
|
| 1093 |
+
organization which should be the folder's new parent.
|
| 1094 |
+
Must be of the form ``folders/{folder_id}`` or
|
| 1095 |
+
``organizations/{org_id}``.
|
| 1096 |
+
|
| 1097 |
+
This corresponds to the ``destination_parent`` field
|
| 1098 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 1099 |
+
should not be set.
|
| 1100 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 1101 |
+
should be retried.
|
| 1102 |
+
timeout (float): The timeout for this request.
|
| 1103 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 1104 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 1105 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 1106 |
+
be of type `bytes`.
|
| 1107 |
+
|
| 1108 |
+
Returns:
|
| 1109 |
+
google.api_core.operation_async.AsyncOperation:
|
| 1110 |
+
An object representing a long-running operation.
|
| 1111 |
+
|
| 1112 |
+
The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Folder` A folder in an organization's resource hierarchy, used to
|
| 1113 |
+
organize that organization's resources.
|
| 1114 |
+
|
| 1115 |
+
"""
|
| 1116 |
+
# Create or coerce a protobuf request object.
|
| 1117 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 1118 |
+
# gotten any keyword arguments that map to the request.
|
| 1119 |
+
flattened_params = [name, destination_parent]
|
| 1120 |
+
has_flattened_params = (
|
| 1121 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 1122 |
+
)
|
| 1123 |
+
if request is not None and has_flattened_params:
|
| 1124 |
+
raise ValueError(
|
| 1125 |
+
"If the `request` argument is set, then none of "
|
| 1126 |
+
"the individual field arguments should be set."
|
| 1127 |
+
)
|
| 1128 |
+
|
| 1129 |
+
# - Use the request object if provided (there's no risk of modifying the input as
|
| 1130 |
+
# there are no flattened fields), or create one.
|
| 1131 |
+
if not isinstance(request, folders.MoveFolderRequest):
|
| 1132 |
+
request = folders.MoveFolderRequest(request)
|
| 1133 |
+
|
| 1134 |
+
# If we have keyword arguments corresponding to fields on the
|
| 1135 |
+
# request, apply these.
|
| 1136 |
+
if name is not None:
|
| 1137 |
+
request.name = name
|
| 1138 |
+
if destination_parent is not None:
|
| 1139 |
+
request.destination_parent = destination_parent
|
| 1140 |
+
|
| 1141 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 1142 |
+
# and friendly error handling.
|
| 1143 |
+
rpc = self._client._transport._wrapped_methods[
|
| 1144 |
+
self._client._transport.move_folder
|
| 1145 |
+
]
|
| 1146 |
+
|
| 1147 |
+
# Certain fields should be provided within the metadata header;
|
| 1148 |
+
# add these here.
|
| 1149 |
+
metadata = tuple(metadata) + (
|
| 1150 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 1151 |
+
)
|
| 1152 |
+
|
| 1153 |
+
# Validate the universe domain.
|
| 1154 |
+
self._client._validate_universe_domain()
|
| 1155 |
+
|
| 1156 |
+
# Send the request.
|
| 1157 |
+
response = await rpc(
|
| 1158 |
+
request,
|
| 1159 |
+
retry=retry,
|
| 1160 |
+
timeout=timeout,
|
| 1161 |
+
metadata=metadata,
|
| 1162 |
+
)
|
| 1163 |
+
|
| 1164 |
+
# Wrap the response in an operation future.
|
| 1165 |
+
response = operation_async.from_gapic(
|
| 1166 |
+
response,
|
| 1167 |
+
self._client._transport.operations_client,
|
| 1168 |
+
folders.Folder,
|
| 1169 |
+
metadata_type=folders.MoveFolderMetadata,
|
| 1170 |
+
)
|
| 1171 |
+
|
| 1172 |
+
# Done; return the response.
|
| 1173 |
+
return response
|
| 1174 |
+
|
| 1175 |
+
async def delete_folder(
|
| 1176 |
+
self,
|
| 1177 |
+
request: Optional[Union[folders.DeleteFolderRequest, dict]] = None,
|
| 1178 |
+
*,
|
| 1179 |
+
name: Optional[str] = None,
|
| 1180 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 1181 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 1182 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 1183 |
+
) -> operation_async.AsyncOperation:
|
| 1184 |
+
r"""Requests deletion of a folder. The folder is moved into the
|
| 1185 |
+
[DELETE_REQUESTED][google.cloud.resourcemanager.v3.Folder.State.DELETE_REQUESTED]
|
| 1186 |
+
state immediately, and is deleted approximately 30 days later.
|
| 1187 |
+
This method may only be called on an empty folder, where a
|
| 1188 |
+
folder is empty if it doesn't contain any folders or projects in
|
| 1189 |
+
the
|
| 1190 |
+
[ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE]
|
| 1191 |
+
state. If called on a folder in
|
| 1192 |
+
[DELETE_REQUESTED][google.cloud.resourcemanager.v3.Folder.State.DELETE_REQUESTED]
|
| 1193 |
+
state the operation will result in a no-op success. The caller
|
| 1194 |
+
must have ``resourcemanager.folders.delete`` permission on the
|
| 1195 |
+
identified folder.
|
| 1196 |
+
|
| 1197 |
+
.. code-block:: python
|
| 1198 |
+
|
| 1199 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 1200 |
+
# code template only.
|
| 1201 |
+
# It will require modifications to work:
|
| 1202 |
+
# - It may require correct/in-range values for request initialization.
|
| 1203 |
+
# - It may require specifying regional endpoints when creating the service
|
| 1204 |
+
# client as shown in:
|
| 1205 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 1206 |
+
from google.cloud import resourcemanager_v3
|
| 1207 |
+
|
| 1208 |
+
async def sample_delete_folder():
|
| 1209 |
+
# Create a client
|
| 1210 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 1211 |
+
|
| 1212 |
+
# Initialize request argument(s)
|
| 1213 |
+
request = resourcemanager_v3.DeleteFolderRequest(
|
| 1214 |
+
name="name_value",
|
| 1215 |
+
)
|
| 1216 |
+
|
| 1217 |
+
# Make the request
|
| 1218 |
+
operation = client.delete_folder(request=request)
|
| 1219 |
+
|
| 1220 |
+
print("Waiting for operation to complete...")
|
| 1221 |
+
|
| 1222 |
+
response = (await operation).result()
|
| 1223 |
+
|
| 1224 |
+
# Handle the response
|
| 1225 |
+
print(response)
|
| 1226 |
+
|
| 1227 |
+
Args:
|
| 1228 |
+
request (Optional[Union[google.cloud.resourcemanager_v3.types.DeleteFolderRequest, dict]]):
|
| 1229 |
+
The request object. The DeleteFolder request message.
|
| 1230 |
+
name (:class:`str`):
|
| 1231 |
+
Required. The resource name of the folder to be deleted.
|
| 1232 |
+
Must be of the form ``folders/{folder_id}``.
|
| 1233 |
+
|
| 1234 |
+
This corresponds to the ``name`` field
|
| 1235 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 1236 |
+
should not be set.
|
| 1237 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 1238 |
+
should be retried.
|
| 1239 |
+
timeout (float): The timeout for this request.
|
| 1240 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 1241 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 1242 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 1243 |
+
be of type `bytes`.
|
| 1244 |
+
|
| 1245 |
+
Returns:
|
| 1246 |
+
google.api_core.operation_async.AsyncOperation:
|
| 1247 |
+
An object representing a long-running operation.
|
| 1248 |
+
|
| 1249 |
+
The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Folder` A folder in an organization's resource hierarchy, used to
|
| 1250 |
+
organize that organization's resources.
|
| 1251 |
+
|
| 1252 |
+
"""
|
| 1253 |
+
# Create or coerce a protobuf request object.
|
| 1254 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 1255 |
+
# gotten any keyword arguments that map to the request.
|
| 1256 |
+
flattened_params = [name]
|
| 1257 |
+
has_flattened_params = (
|
| 1258 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 1259 |
+
)
|
| 1260 |
+
if request is not None and has_flattened_params:
|
| 1261 |
+
raise ValueError(
|
| 1262 |
+
"If the `request` argument is set, then none of "
|
| 1263 |
+
"the individual field arguments should be set."
|
| 1264 |
+
)
|
| 1265 |
+
|
| 1266 |
+
# - Use the request object if provided (there's no risk of modifying the input as
|
| 1267 |
+
# there are no flattened fields), or create one.
|
| 1268 |
+
if not isinstance(request, folders.DeleteFolderRequest):
|
| 1269 |
+
request = folders.DeleteFolderRequest(request)
|
| 1270 |
+
|
| 1271 |
+
# If we have keyword arguments corresponding to fields on the
|
| 1272 |
+
# request, apply these.
|
| 1273 |
+
if name is not None:
|
| 1274 |
+
request.name = name
|
| 1275 |
+
|
| 1276 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 1277 |
+
# and friendly error handling.
|
| 1278 |
+
rpc = self._client._transport._wrapped_methods[
|
| 1279 |
+
self._client._transport.delete_folder
|
| 1280 |
+
]
|
| 1281 |
+
|
| 1282 |
+
# Certain fields should be provided within the metadata header;
|
| 1283 |
+
# add these here.
|
| 1284 |
+
metadata = tuple(metadata) + (
|
| 1285 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 1286 |
+
)
|
| 1287 |
+
|
| 1288 |
+
# Validate the universe domain.
|
| 1289 |
+
self._client._validate_universe_domain()
|
| 1290 |
+
|
| 1291 |
+
# Send the request.
|
| 1292 |
+
response = await rpc(
|
| 1293 |
+
request,
|
| 1294 |
+
retry=retry,
|
| 1295 |
+
timeout=timeout,
|
| 1296 |
+
metadata=metadata,
|
| 1297 |
+
)
|
| 1298 |
+
|
| 1299 |
+
# Wrap the response in an operation future.
|
| 1300 |
+
response = operation_async.from_gapic(
|
| 1301 |
+
response,
|
| 1302 |
+
self._client._transport.operations_client,
|
| 1303 |
+
folders.Folder,
|
| 1304 |
+
metadata_type=folders.DeleteFolderMetadata,
|
| 1305 |
+
)
|
| 1306 |
+
|
| 1307 |
+
# Done; return the response.
|
| 1308 |
+
return response
|
| 1309 |
+
|
| 1310 |
+
async def undelete_folder(
|
| 1311 |
+
self,
|
| 1312 |
+
request: Optional[Union[folders.UndeleteFolderRequest, dict]] = None,
|
| 1313 |
+
*,
|
| 1314 |
+
name: Optional[str] = None,
|
| 1315 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 1316 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 1317 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 1318 |
+
) -> operation_async.AsyncOperation:
|
| 1319 |
+
r"""Cancels the deletion request for a folder. This method may be
|
| 1320 |
+
called on a folder in any state. If the folder is in the
|
| 1321 |
+
[ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE]
|
| 1322 |
+
state the result will be a no-op success. In order to succeed,
|
| 1323 |
+
the folder's parent must be in the
|
| 1324 |
+
[ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE]
|
| 1325 |
+
state. In addition, reintroducing the folder into the tree must
|
| 1326 |
+
not violate folder naming, height, and fanout constraints
|
| 1327 |
+
described in the
|
| 1328 |
+
[CreateFolder][google.cloud.resourcemanager.v3.Folders.CreateFolder]
|
| 1329 |
+
documentation. The caller must have
|
| 1330 |
+
``resourcemanager.folders.undelete`` permission on the
|
| 1331 |
+
identified folder.
|
| 1332 |
+
|
| 1333 |
+
.. code-block:: python
|
| 1334 |
+
|
| 1335 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 1336 |
+
# code template only.
|
| 1337 |
+
# It will require modifications to work:
|
| 1338 |
+
# - It may require correct/in-range values for request initialization.
|
| 1339 |
+
# - It may require specifying regional endpoints when creating the service
|
| 1340 |
+
# client as shown in:
|
| 1341 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 1342 |
+
from google.cloud import resourcemanager_v3
|
| 1343 |
+
|
| 1344 |
+
async def sample_undelete_folder():
|
| 1345 |
+
# Create a client
|
| 1346 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 1347 |
+
|
| 1348 |
+
# Initialize request argument(s)
|
| 1349 |
+
request = resourcemanager_v3.UndeleteFolderRequest(
|
| 1350 |
+
name="name_value",
|
| 1351 |
+
)
|
| 1352 |
+
|
| 1353 |
+
# Make the request
|
| 1354 |
+
operation = client.undelete_folder(request=request)
|
| 1355 |
+
|
| 1356 |
+
print("Waiting for operation to complete...")
|
| 1357 |
+
|
| 1358 |
+
response = (await operation).result()
|
| 1359 |
+
|
| 1360 |
+
# Handle the response
|
| 1361 |
+
print(response)
|
| 1362 |
+
|
| 1363 |
+
Args:
|
| 1364 |
+
request (Optional[Union[google.cloud.resourcemanager_v3.types.UndeleteFolderRequest, dict]]):
|
| 1365 |
+
The request object. The UndeleteFolder request message.
|
| 1366 |
+
name (:class:`str`):
|
| 1367 |
+
Required. The resource name of the folder to undelete.
|
| 1368 |
+
Must be of the form ``folders/{folder_id}``.
|
| 1369 |
+
|
| 1370 |
+
This corresponds to the ``name`` field
|
| 1371 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 1372 |
+
should not be set.
|
| 1373 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 1374 |
+
should be retried.
|
| 1375 |
+
timeout (float): The timeout for this request.
|
| 1376 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 1377 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 1378 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 1379 |
+
be of type `bytes`.
|
| 1380 |
+
|
| 1381 |
+
Returns:
|
| 1382 |
+
google.api_core.operation_async.AsyncOperation:
|
| 1383 |
+
An object representing a long-running operation.
|
| 1384 |
+
|
| 1385 |
+
The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Folder` A folder in an organization's resource hierarchy, used to
|
| 1386 |
+
organize that organization's resources.
|
| 1387 |
+
|
| 1388 |
+
"""
|
| 1389 |
+
# Create or coerce a protobuf request object.
|
| 1390 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 1391 |
+
# gotten any keyword arguments that map to the request.
|
| 1392 |
+
flattened_params = [name]
|
| 1393 |
+
has_flattened_params = (
|
| 1394 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 1395 |
+
)
|
| 1396 |
+
if request is not None and has_flattened_params:
|
| 1397 |
+
raise ValueError(
|
| 1398 |
+
"If the `request` argument is set, then none of "
|
| 1399 |
+
"the individual field arguments should be set."
|
| 1400 |
+
)
|
| 1401 |
+
|
| 1402 |
+
# - Use the request object if provided (there's no risk of modifying the input as
|
| 1403 |
+
# there are no flattened fields), or create one.
|
| 1404 |
+
if not isinstance(request, folders.UndeleteFolderRequest):
|
| 1405 |
+
request = folders.UndeleteFolderRequest(request)
|
| 1406 |
+
|
| 1407 |
+
# If we have keyword arguments corresponding to fields on the
|
| 1408 |
+
# request, apply these.
|
| 1409 |
+
if name is not None:
|
| 1410 |
+
request.name = name
|
| 1411 |
+
|
| 1412 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 1413 |
+
# and friendly error handling.
|
| 1414 |
+
rpc = self._client._transport._wrapped_methods[
|
| 1415 |
+
self._client._transport.undelete_folder
|
| 1416 |
+
]
|
| 1417 |
+
|
| 1418 |
+
# Certain fields should be provided within the metadata header;
|
| 1419 |
+
# add these here.
|
| 1420 |
+
metadata = tuple(metadata) + (
|
| 1421 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 1422 |
+
)
|
| 1423 |
+
|
| 1424 |
+
# Validate the universe domain.
|
| 1425 |
+
self._client._validate_universe_domain()
|
| 1426 |
+
|
| 1427 |
+
# Send the request.
|
| 1428 |
+
response = await rpc(
|
| 1429 |
+
request,
|
| 1430 |
+
retry=retry,
|
| 1431 |
+
timeout=timeout,
|
| 1432 |
+
metadata=metadata,
|
| 1433 |
+
)
|
| 1434 |
+
|
| 1435 |
+
# Wrap the response in an operation future.
|
| 1436 |
+
response = operation_async.from_gapic(
|
| 1437 |
+
response,
|
| 1438 |
+
self._client._transport.operations_client,
|
| 1439 |
+
folders.Folder,
|
| 1440 |
+
metadata_type=folders.UndeleteFolderMetadata,
|
| 1441 |
+
)
|
| 1442 |
+
|
| 1443 |
+
# Done; return the response.
|
| 1444 |
+
return response
|
| 1445 |
+
|
| 1446 |
+
async def get_iam_policy(
|
| 1447 |
+
self,
|
| 1448 |
+
request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None,
|
| 1449 |
+
*,
|
| 1450 |
+
resource: Optional[str] = None,
|
| 1451 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 1452 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 1453 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 1454 |
+
) -> policy_pb2.Policy:
|
| 1455 |
+
r"""Gets the access control policy for a folder. The returned policy
|
| 1456 |
+
may be empty if no such policy or resource exists. The
|
| 1457 |
+
``resource`` field should be the folder's resource name, for
|
| 1458 |
+
example: "folders/1234". The caller must have
|
| 1459 |
+
``resourcemanager.folders.getIamPolicy`` permission on the
|
| 1460 |
+
identified folder.
|
| 1461 |
+
|
| 1462 |
+
.. code-block:: python
|
| 1463 |
+
|
| 1464 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 1465 |
+
# code template only.
|
| 1466 |
+
# It will require modifications to work:
|
| 1467 |
+
# - It may require correct/in-range values for request initialization.
|
| 1468 |
+
# - It may require specifying regional endpoints when creating the service
|
| 1469 |
+
# client as shown in:
|
| 1470 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 1471 |
+
from google.cloud import resourcemanager_v3
|
| 1472 |
+
import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore
|
| 1473 |
+
|
| 1474 |
+
async def sample_get_iam_policy():
|
| 1475 |
+
# Create a client
|
| 1476 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 1477 |
+
|
| 1478 |
+
# Initialize request argument(s)
|
| 1479 |
+
request = iam_policy_pb2.GetIamPolicyRequest(
|
| 1480 |
+
resource="resource_value",
|
| 1481 |
+
)
|
| 1482 |
+
|
| 1483 |
+
# Make the request
|
| 1484 |
+
response = await client.get_iam_policy(request=request)
|
| 1485 |
+
|
| 1486 |
+
# Handle the response
|
| 1487 |
+
print(response)
|
| 1488 |
+
|
| 1489 |
+
Args:
|
| 1490 |
+
request (Optional[Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]]):
|
| 1491 |
+
The request object. Request message for ``GetIamPolicy`` method.
|
| 1492 |
+
resource (:class:`str`):
|
| 1493 |
+
REQUIRED: The resource for which the
|
| 1494 |
+
policy is being requested. See the
|
| 1495 |
+
operation documentation for the
|
| 1496 |
+
appropriate value for this field.
|
| 1497 |
+
|
| 1498 |
+
This corresponds to the ``resource`` field
|
| 1499 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 1500 |
+
should not be set.
|
| 1501 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 1502 |
+
should be retried.
|
| 1503 |
+
timeout (float): The timeout for this request.
|
| 1504 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 1505 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 1506 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 1507 |
+
be of type `bytes`.
|
| 1508 |
+
|
| 1509 |
+
Returns:
|
| 1510 |
+
google.iam.v1.policy_pb2.Policy:
|
| 1511 |
+
An Identity and Access Management (IAM) policy, which specifies access
|
| 1512 |
+
controls for Google Cloud resources.
|
| 1513 |
+
|
| 1514 |
+
A Policy is a collection of bindings. A binding binds
|
| 1515 |
+
one or more members, or principals, to a single role.
|
| 1516 |
+
Principals can be user accounts, service accounts,
|
| 1517 |
+
Google groups, and domains (such as G Suite). A role
|
| 1518 |
+
is a named list of permissions; each role can be an
|
| 1519 |
+
IAM predefined role or a user-created custom role.
|
| 1520 |
+
|
| 1521 |
+
For some types of Google Cloud resources, a binding
|
| 1522 |
+
can also specify a condition, which is a logical
|
| 1523 |
+
expression that allows access to a resource only if
|
| 1524 |
+
the expression evaluates to true. A condition can add
|
| 1525 |
+
constraints based on attributes of the request, the
|
| 1526 |
+
resource, or both. To learn which resources support
|
| 1527 |
+
conditions in their IAM policies, see the [IAM
|
| 1528 |
+
documentation](https://cloud.google.com/iam/help/conditions/resource-policies).
|
| 1529 |
+
|
| 1530 |
+
**JSON example:**
|
| 1531 |
+
|
| 1532 |
+
:literal:`` { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 }`\ \`
|
| 1533 |
+
|
| 1534 |
+
**YAML example:**
|
| 1535 |
+
|
| 1536 |
+
:literal:`` bindings: - members: - user:mike@example.com - group:admins@example.com - domain:google.com - serviceAccount:my-project-id@appspot.gserviceaccount.com role: roles/resourcemanager.organizationAdmin - members: - user:eve@example.com role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3`\ \`
|
| 1537 |
+
|
| 1538 |
+
For a description of IAM and its features, see the
|
| 1539 |
+
[IAM
|
| 1540 |
+
documentation](https://cloud.google.com/iam/docs/).
|
| 1541 |
+
|
| 1542 |
+
"""
|
| 1543 |
+
# Create or coerce a protobuf request object.
|
| 1544 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 1545 |
+
# gotten any keyword arguments that map to the request.
|
| 1546 |
+
flattened_params = [resource]
|
| 1547 |
+
has_flattened_params = (
|
| 1548 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 1549 |
+
)
|
| 1550 |
+
if request is not None and has_flattened_params:
|
| 1551 |
+
raise ValueError(
|
| 1552 |
+
"If the `request` argument is set, then none of "
|
| 1553 |
+
"the individual field arguments should be set."
|
| 1554 |
+
)
|
| 1555 |
+
|
| 1556 |
+
# - The request isn't a proto-plus wrapped type,
|
| 1557 |
+
# so it must be constructed via keyword expansion.
|
| 1558 |
+
if isinstance(request, dict):
|
| 1559 |
+
request = iam_policy_pb2.GetIamPolicyRequest(**request)
|
| 1560 |
+
elif not request:
|
| 1561 |
+
request = iam_policy_pb2.GetIamPolicyRequest(resource=resource)
|
| 1562 |
+
|
| 1563 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 1564 |
+
# and friendly error handling.
|
| 1565 |
+
rpc = self._client._transport._wrapped_methods[
|
| 1566 |
+
self._client._transport.get_iam_policy
|
| 1567 |
+
]
|
| 1568 |
+
|
| 1569 |
+
# Certain fields should be provided within the metadata header;
|
| 1570 |
+
# add these here.
|
| 1571 |
+
metadata = tuple(metadata) + (
|
| 1572 |
+
gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
|
| 1573 |
+
)
|
| 1574 |
+
|
| 1575 |
+
# Validate the universe domain.
|
| 1576 |
+
self._client._validate_universe_domain()
|
| 1577 |
+
|
| 1578 |
+
# Send the request.
|
| 1579 |
+
response = await rpc(
|
| 1580 |
+
request,
|
| 1581 |
+
retry=retry,
|
| 1582 |
+
timeout=timeout,
|
| 1583 |
+
metadata=metadata,
|
| 1584 |
+
)
|
| 1585 |
+
|
| 1586 |
+
# Done; return the response.
|
| 1587 |
+
return response
|
| 1588 |
+
|
| 1589 |
+
async def set_iam_policy(
|
| 1590 |
+
self,
|
| 1591 |
+
request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None,
|
| 1592 |
+
*,
|
| 1593 |
+
resource: Optional[str] = None,
|
| 1594 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 1595 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 1596 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 1597 |
+
) -> policy_pb2.Policy:
|
| 1598 |
+
r"""Sets the access control policy on a folder, replacing any
|
| 1599 |
+
existing policy. The ``resource`` field should be the folder's
|
| 1600 |
+
resource name, for example: "folders/1234". The caller must have
|
| 1601 |
+
``resourcemanager.folders.setIamPolicy`` permission on the
|
| 1602 |
+
identified folder.
|
| 1603 |
+
|
| 1604 |
+
.. code-block:: python
|
| 1605 |
+
|
| 1606 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 1607 |
+
# code template only.
|
| 1608 |
+
# It will require modifications to work:
|
| 1609 |
+
# - It may require correct/in-range values for request initialization.
|
| 1610 |
+
# - It may require specifying regional endpoints when creating the service
|
| 1611 |
+
# client as shown in:
|
| 1612 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 1613 |
+
from google.cloud import resourcemanager_v3
|
| 1614 |
+
import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore
|
| 1615 |
+
|
| 1616 |
+
async def sample_set_iam_policy():
|
| 1617 |
+
# Create a client
|
| 1618 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 1619 |
+
|
| 1620 |
+
# Initialize request argument(s)
|
| 1621 |
+
request = iam_policy_pb2.SetIamPolicyRequest(
|
| 1622 |
+
resource="resource_value",
|
| 1623 |
+
)
|
| 1624 |
+
|
| 1625 |
+
# Make the request
|
| 1626 |
+
response = await client.set_iam_policy(request=request)
|
| 1627 |
+
|
| 1628 |
+
# Handle the response
|
| 1629 |
+
print(response)
|
| 1630 |
+
|
| 1631 |
+
Args:
|
| 1632 |
+
request (Optional[Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]]):
|
| 1633 |
+
The request object. Request message for ``SetIamPolicy`` method.
|
| 1634 |
+
resource (:class:`str`):
|
| 1635 |
+
REQUIRED: The resource for which the
|
| 1636 |
+
policy is being specified. See the
|
| 1637 |
+
operation documentation for the
|
| 1638 |
+
appropriate value for this field.
|
| 1639 |
+
|
| 1640 |
+
This corresponds to the ``resource`` field
|
| 1641 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 1642 |
+
should not be set.
|
| 1643 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 1644 |
+
should be retried.
|
| 1645 |
+
timeout (float): The timeout for this request.
|
| 1646 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 1647 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 1648 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 1649 |
+
be of type `bytes`.
|
| 1650 |
+
|
| 1651 |
+
Returns:
|
| 1652 |
+
google.iam.v1.policy_pb2.Policy:
|
| 1653 |
+
An Identity and Access Management (IAM) policy, which specifies access
|
| 1654 |
+
controls for Google Cloud resources.
|
| 1655 |
+
|
| 1656 |
+
A Policy is a collection of bindings. A binding binds
|
| 1657 |
+
one or more members, or principals, to a single role.
|
| 1658 |
+
Principals can be user accounts, service accounts,
|
| 1659 |
+
Google groups, and domains (such as G Suite). A role
|
| 1660 |
+
is a named list of permissions; each role can be an
|
| 1661 |
+
IAM predefined role or a user-created custom role.
|
| 1662 |
+
|
| 1663 |
+
For some types of Google Cloud resources, a binding
|
| 1664 |
+
can also specify a condition, which is a logical
|
| 1665 |
+
expression that allows access to a resource only if
|
| 1666 |
+
the expression evaluates to true. A condition can add
|
| 1667 |
+
constraints based on attributes of the request, the
|
| 1668 |
+
resource, or both. To learn which resources support
|
| 1669 |
+
conditions in their IAM policies, see the [IAM
|
| 1670 |
+
documentation](https://cloud.google.com/iam/help/conditions/resource-policies).
|
| 1671 |
+
|
| 1672 |
+
**JSON example:**
|
| 1673 |
+
|
| 1674 |
+
:literal:`` { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 }`\ \`
|
| 1675 |
+
|
| 1676 |
+
**YAML example:**
|
| 1677 |
+
|
| 1678 |
+
:literal:`` bindings: - members: - user:mike@example.com - group:admins@example.com - domain:google.com - serviceAccount:my-project-id@appspot.gserviceaccount.com role: roles/resourcemanager.organizationAdmin - members: - user:eve@example.com role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3`\ \`
|
| 1679 |
+
|
| 1680 |
+
For a description of IAM and its features, see the
|
| 1681 |
+
[IAM
|
| 1682 |
+
documentation](https://cloud.google.com/iam/docs/).
|
| 1683 |
+
|
| 1684 |
+
"""
|
| 1685 |
+
# Create or coerce a protobuf request object.
|
| 1686 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 1687 |
+
# gotten any keyword arguments that map to the request.
|
| 1688 |
+
flattened_params = [resource]
|
| 1689 |
+
has_flattened_params = (
|
| 1690 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 1691 |
+
)
|
| 1692 |
+
if request is not None and has_flattened_params:
|
| 1693 |
+
raise ValueError(
|
| 1694 |
+
"If the `request` argument is set, then none of "
|
| 1695 |
+
"the individual field arguments should be set."
|
| 1696 |
+
)
|
| 1697 |
+
|
| 1698 |
+
# - The request isn't a proto-plus wrapped type,
|
| 1699 |
+
# so it must be constructed via keyword expansion.
|
| 1700 |
+
if isinstance(request, dict):
|
| 1701 |
+
request = iam_policy_pb2.SetIamPolicyRequest(**request)
|
| 1702 |
+
elif not request:
|
| 1703 |
+
request = iam_policy_pb2.SetIamPolicyRequest(resource=resource)
|
| 1704 |
+
|
| 1705 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 1706 |
+
# and friendly error handling.
|
| 1707 |
+
rpc = self._client._transport._wrapped_methods[
|
| 1708 |
+
self._client._transport.set_iam_policy
|
| 1709 |
+
]
|
| 1710 |
+
|
| 1711 |
+
# Certain fields should be provided within the metadata header;
|
| 1712 |
+
# add these here.
|
| 1713 |
+
metadata = tuple(metadata) + (
|
| 1714 |
+
gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
|
| 1715 |
+
)
|
| 1716 |
+
|
| 1717 |
+
# Validate the universe domain.
|
| 1718 |
+
self._client._validate_universe_domain()
|
| 1719 |
+
|
| 1720 |
+
# Send the request.
|
| 1721 |
+
response = await rpc(
|
| 1722 |
+
request,
|
| 1723 |
+
retry=retry,
|
| 1724 |
+
timeout=timeout,
|
| 1725 |
+
metadata=metadata,
|
| 1726 |
+
)
|
| 1727 |
+
|
| 1728 |
+
# Done; return the response.
|
| 1729 |
+
return response
|
| 1730 |
+
|
| 1731 |
+
async def test_iam_permissions(
|
| 1732 |
+
self,
|
| 1733 |
+
request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None,
|
| 1734 |
+
*,
|
| 1735 |
+
resource: Optional[str] = None,
|
| 1736 |
+
permissions: Optional[MutableSequence[str]] = None,
|
| 1737 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 1738 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 1739 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 1740 |
+
) -> iam_policy_pb2.TestIamPermissionsResponse:
|
| 1741 |
+
r"""Returns permissions that a caller has on the specified folder.
|
| 1742 |
+
The ``resource`` field should be the folder's resource name, for
|
| 1743 |
+
example: "folders/1234".
|
| 1744 |
+
|
| 1745 |
+
There are no permissions required for making this API call.
|
| 1746 |
+
|
| 1747 |
+
.. code-block:: python
|
| 1748 |
+
|
| 1749 |
+
# This snippet has been automatically generated and should be regarded as a
|
| 1750 |
+
# code template only.
|
| 1751 |
+
# It will require modifications to work:
|
| 1752 |
+
# - It may require correct/in-range values for request initialization.
|
| 1753 |
+
# - It may require specifying regional endpoints when creating the service
|
| 1754 |
+
# client as shown in:
|
| 1755 |
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
| 1756 |
+
from google.cloud import resourcemanager_v3
|
| 1757 |
+
import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore
|
| 1758 |
+
|
| 1759 |
+
async def sample_test_iam_permissions():
|
| 1760 |
+
# Create a client
|
| 1761 |
+
client = resourcemanager_v3.FoldersAsyncClient()
|
| 1762 |
+
|
| 1763 |
+
# Initialize request argument(s)
|
| 1764 |
+
request = iam_policy_pb2.TestIamPermissionsRequest(
|
| 1765 |
+
resource="resource_value",
|
| 1766 |
+
permissions=['permissions_value1', 'permissions_value2'],
|
| 1767 |
+
)
|
| 1768 |
+
|
| 1769 |
+
# Make the request
|
| 1770 |
+
response = await client.test_iam_permissions(request=request)
|
| 1771 |
+
|
| 1772 |
+
# Handle the response
|
| 1773 |
+
print(response)
|
| 1774 |
+
|
| 1775 |
+
Args:
|
| 1776 |
+
request (Optional[Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]]):
|
| 1777 |
+
The request object. Request message for ``TestIamPermissions`` method.
|
| 1778 |
+
resource (:class:`str`):
|
| 1779 |
+
REQUIRED: The resource for which the
|
| 1780 |
+
policy detail is being requested. See
|
| 1781 |
+
the operation documentation for the
|
| 1782 |
+
appropriate value for this field.
|
| 1783 |
+
|
| 1784 |
+
This corresponds to the ``resource`` field
|
| 1785 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 1786 |
+
should not be set.
|
| 1787 |
+
permissions (:class:`MutableSequence[str]`):
|
| 1788 |
+
The set of permissions to check for the ``resource``.
|
| 1789 |
+
Permissions with wildcards (such as '*' or 'storage.*')
|
| 1790 |
+
are not allowed. For more information see `IAM
|
| 1791 |
+
Overview <https://cloud.google.com/iam/docs/overview#permissions>`__.
|
| 1792 |
+
|
| 1793 |
+
This corresponds to the ``permissions`` field
|
| 1794 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 1795 |
+
should not be set.
|
| 1796 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
|
| 1797 |
+
should be retried.
|
| 1798 |
+
timeout (float): The timeout for this request.
|
| 1799 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 1800 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 1801 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 1802 |
+
be of type `bytes`.
|
| 1803 |
+
|
| 1804 |
+
Returns:
|
| 1805 |
+
google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse:
|
| 1806 |
+
Response message for TestIamPermissions method.
|
| 1807 |
+
"""
|
| 1808 |
+
# Create or coerce a protobuf request object.
|
| 1809 |
+
# - Quick check: If we got a request object, we should *not* have
|
| 1810 |
+
# gotten any keyword arguments that map to the request.
|
| 1811 |
+
flattened_params = [resource, permissions]
|
| 1812 |
+
has_flattened_params = (
|
| 1813 |
+
len([param for param in flattened_params if param is not None]) > 0
|
| 1814 |
+
)
|
| 1815 |
+
if request is not None and has_flattened_params:
|
| 1816 |
+
raise ValueError(
|
| 1817 |
+
"If the `request` argument is set, then none of "
|
| 1818 |
+
"the individual field arguments should be set."
|
| 1819 |
+
)
|
| 1820 |
+
|
| 1821 |
+
# - The request isn't a proto-plus wrapped type,
|
| 1822 |
+
# so it must be constructed via keyword expansion.
|
| 1823 |
+
if isinstance(request, dict):
|
| 1824 |
+
request = iam_policy_pb2.TestIamPermissionsRequest(**request)
|
| 1825 |
+
elif not request:
|
| 1826 |
+
request = iam_policy_pb2.TestIamPermissionsRequest(
|
| 1827 |
+
resource=resource, permissions=permissions
|
| 1828 |
+
)
|
| 1829 |
+
|
| 1830 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 1831 |
+
# and friendly error handling.
|
| 1832 |
+
rpc = self._client._transport._wrapped_methods[
|
| 1833 |
+
self._client._transport.test_iam_permissions
|
| 1834 |
+
]
|
| 1835 |
+
|
| 1836 |
+
# Certain fields should be provided within the metadata header;
|
| 1837 |
+
# add these here.
|
| 1838 |
+
metadata = tuple(metadata) + (
|
| 1839 |
+
gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
|
| 1840 |
+
)
|
| 1841 |
+
|
| 1842 |
+
# Validate the universe domain.
|
| 1843 |
+
self._client._validate_universe_domain()
|
| 1844 |
+
|
| 1845 |
+
# Send the request.
|
| 1846 |
+
response = await rpc(
|
| 1847 |
+
request,
|
| 1848 |
+
retry=retry,
|
| 1849 |
+
timeout=timeout,
|
| 1850 |
+
metadata=metadata,
|
| 1851 |
+
)
|
| 1852 |
+
|
| 1853 |
+
# Done; return the response.
|
| 1854 |
+
return response
|
| 1855 |
+
|
| 1856 |
+
async def get_operation(
|
| 1857 |
+
self,
|
| 1858 |
+
request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None,
|
| 1859 |
+
*,
|
| 1860 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 1861 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 1862 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 1863 |
+
) -> operations_pb2.Operation:
|
| 1864 |
+
r"""Gets the latest state of a long-running operation.
|
| 1865 |
+
|
| 1866 |
+
Args:
|
| 1867 |
+
request (:class:`~.operations_pb2.GetOperationRequest`):
|
| 1868 |
+
The request object. Request message for
|
| 1869 |
+
`GetOperation` method.
|
| 1870 |
+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors,
|
| 1871 |
+
if any, should be retried.
|
| 1872 |
+
timeout (float): The timeout for this request.
|
| 1873 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 1874 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 1875 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 1876 |
+
be of type `bytes`.
|
| 1877 |
+
Returns:
|
| 1878 |
+
~.operations_pb2.Operation:
|
| 1879 |
+
An ``Operation`` object.
|
| 1880 |
+
"""
|
| 1881 |
+
# Create or coerce a protobuf request object.
|
| 1882 |
+
# The request isn't a proto-plus wrapped type,
|
| 1883 |
+
# so it must be constructed via keyword expansion.
|
| 1884 |
+
if request is None:
|
| 1885 |
+
request_pb = operations_pb2.GetOperationRequest()
|
| 1886 |
+
elif isinstance(request, dict):
|
| 1887 |
+
request_pb = operations_pb2.GetOperationRequest(**request)
|
| 1888 |
+
else:
|
| 1889 |
+
request_pb = request
|
| 1890 |
+
|
| 1891 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 1892 |
+
# and friendly error handling.
|
| 1893 |
+
rpc = self.transport._wrapped_methods[self._client._transport.get_operation]
|
| 1894 |
+
|
| 1895 |
+
# Certain fields should be provided within the metadata header;
|
| 1896 |
+
# add these here.
|
| 1897 |
+
metadata = tuple(metadata) + (
|
| 1898 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)),
|
| 1899 |
+
)
|
| 1900 |
+
|
| 1901 |
+
# Validate the universe domain.
|
| 1902 |
+
self._client._validate_universe_domain()
|
| 1903 |
+
|
| 1904 |
+
# Send the request.
|
| 1905 |
+
response = await rpc(
|
| 1906 |
+
request_pb,
|
| 1907 |
+
retry=retry,
|
| 1908 |
+
timeout=timeout,
|
| 1909 |
+
metadata=metadata,
|
| 1910 |
+
)
|
| 1911 |
+
|
| 1912 |
+
# Done; return the response.
|
| 1913 |
+
return response
|
| 1914 |
+
|
| 1915 |
+
async def __aenter__(self) -> "FoldersAsyncClient":
|
| 1916 |
+
return self
|
| 1917 |
+
|
| 1918 |
+
async def __aexit__(self, exc_type, exc, tb):
|
| 1919 |
+
await self.transport.close()
|
| 1920 |
+
|
| 1921 |
+
|
| 1922 |
+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
|
| 1923 |
+
gapic_version=package_version.__version__
|
| 1924 |
+
)
|
| 1925 |
+
|
| 1926 |
+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
|
| 1927 |
+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
|
| 1928 |
+
|
| 1929 |
+
|
| 1930 |
+
__all__ = ("FoldersAsyncClient",)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/client.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/pagers.py
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
from typing import (
|
| 17 |
+
Any,
|
| 18 |
+
AsyncIterator,
|
| 19 |
+
Awaitable,
|
| 20 |
+
Callable,
|
| 21 |
+
Iterator,
|
| 22 |
+
Optional,
|
| 23 |
+
Sequence,
|
| 24 |
+
Tuple,
|
| 25 |
+
Union,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
from google.api_core import gapic_v1
|
| 29 |
+
from google.api_core import retry as retries
|
| 30 |
+
from google.api_core import retry_async as retries_async
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
|
| 34 |
+
OptionalAsyncRetry = Union[
|
| 35 |
+
retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None
|
| 36 |
+
]
|
| 37 |
+
except AttributeError: # pragma: NO COVER
|
| 38 |
+
OptionalRetry = Union[retries.Retry, object, None] # type: ignore
|
| 39 |
+
OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore
|
| 40 |
+
|
| 41 |
+
from google.cloud.resourcemanager_v3.types import folders
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class ListFoldersPager:
|
| 45 |
+
"""A pager for iterating through ``list_folders`` requests.
|
| 46 |
+
|
| 47 |
+
This class thinly wraps an initial
|
| 48 |
+
:class:`google.cloud.resourcemanager_v3.types.ListFoldersResponse` object, and
|
| 49 |
+
provides an ``__iter__`` method to iterate through its
|
| 50 |
+
``folders`` field.
|
| 51 |
+
|
| 52 |
+
If there are more pages, the ``__iter__`` method will make additional
|
| 53 |
+
``ListFolders`` requests and continue to iterate
|
| 54 |
+
through the ``folders`` field on the
|
| 55 |
+
corresponding responses.
|
| 56 |
+
|
| 57 |
+
All the usual :class:`google.cloud.resourcemanager_v3.types.ListFoldersResponse`
|
| 58 |
+
attributes are available on the pager. If multiple requests are made, only
|
| 59 |
+
the most recent response is retained, and thus used for attribute lookup.
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
def __init__(
|
| 63 |
+
self,
|
| 64 |
+
method: Callable[..., folders.ListFoldersResponse],
|
| 65 |
+
request: folders.ListFoldersRequest,
|
| 66 |
+
response: folders.ListFoldersResponse,
|
| 67 |
+
*,
|
| 68 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 69 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 70 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 71 |
+
):
|
| 72 |
+
"""Instantiate the pager.
|
| 73 |
+
|
| 74 |
+
Args:
|
| 75 |
+
method (Callable): The method that was originally called, and
|
| 76 |
+
which instantiated this pager.
|
| 77 |
+
request (google.cloud.resourcemanager_v3.types.ListFoldersRequest):
|
| 78 |
+
The initial request object.
|
| 79 |
+
response (google.cloud.resourcemanager_v3.types.ListFoldersResponse):
|
| 80 |
+
The initial response object.
|
| 81 |
+
retry (google.api_core.retry.Retry): Designation of what errors,
|
| 82 |
+
if any, should be retried.
|
| 83 |
+
timeout (float): The timeout for this request.
|
| 84 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 85 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 86 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 87 |
+
be of type `bytes`.
|
| 88 |
+
"""
|
| 89 |
+
self._method = method
|
| 90 |
+
self._request = folders.ListFoldersRequest(request)
|
| 91 |
+
self._response = response
|
| 92 |
+
self._retry = retry
|
| 93 |
+
self._timeout = timeout
|
| 94 |
+
self._metadata = metadata
|
| 95 |
+
|
| 96 |
+
def __getattr__(self, name: str) -> Any:
|
| 97 |
+
return getattr(self._response, name)
|
| 98 |
+
|
| 99 |
+
@property
|
| 100 |
+
def pages(self) -> Iterator[folders.ListFoldersResponse]:
|
| 101 |
+
yield self._response
|
| 102 |
+
while self._response.next_page_token:
|
| 103 |
+
self._request.page_token = self._response.next_page_token
|
| 104 |
+
self._response = self._method(
|
| 105 |
+
self._request,
|
| 106 |
+
retry=self._retry,
|
| 107 |
+
timeout=self._timeout,
|
| 108 |
+
metadata=self._metadata,
|
| 109 |
+
)
|
| 110 |
+
yield self._response
|
| 111 |
+
|
| 112 |
+
def __iter__(self) -> Iterator[folders.Folder]:
|
| 113 |
+
for page in self.pages:
|
| 114 |
+
yield from page.folders
|
| 115 |
+
|
| 116 |
+
def __repr__(self) -> str:
|
| 117 |
+
return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class ListFoldersAsyncPager:
|
| 121 |
+
"""A pager for iterating through ``list_folders`` requests.
|
| 122 |
+
|
| 123 |
+
This class thinly wraps an initial
|
| 124 |
+
:class:`google.cloud.resourcemanager_v3.types.ListFoldersResponse` object, and
|
| 125 |
+
provides an ``__aiter__`` method to iterate through its
|
| 126 |
+
``folders`` field.
|
| 127 |
+
|
| 128 |
+
If there are more pages, the ``__aiter__`` method will make additional
|
| 129 |
+
``ListFolders`` requests and continue to iterate
|
| 130 |
+
through the ``folders`` field on the
|
| 131 |
+
corresponding responses.
|
| 132 |
+
|
| 133 |
+
All the usual :class:`google.cloud.resourcemanager_v3.types.ListFoldersResponse`
|
| 134 |
+
attributes are available on the pager. If multiple requests are made, only
|
| 135 |
+
the most recent response is retained, and thus used for attribute lookup.
|
| 136 |
+
"""
|
| 137 |
+
|
| 138 |
+
def __init__(
|
| 139 |
+
self,
|
| 140 |
+
method: Callable[..., Awaitable[folders.ListFoldersResponse]],
|
| 141 |
+
request: folders.ListFoldersRequest,
|
| 142 |
+
response: folders.ListFoldersResponse,
|
| 143 |
+
*,
|
| 144 |
+
retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
|
| 145 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 146 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 147 |
+
):
|
| 148 |
+
"""Instantiates the pager.
|
| 149 |
+
|
| 150 |
+
Args:
|
| 151 |
+
method (Callable): The method that was originally called, and
|
| 152 |
+
which instantiated this pager.
|
| 153 |
+
request (google.cloud.resourcemanager_v3.types.ListFoldersRequest):
|
| 154 |
+
The initial request object.
|
| 155 |
+
response (google.cloud.resourcemanager_v3.types.ListFoldersResponse):
|
| 156 |
+
The initial response object.
|
| 157 |
+
retry (google.api_core.retry.AsyncRetry): Designation of what errors,
|
| 158 |
+
if any, should be retried.
|
| 159 |
+
timeout (float): The timeout for this request.
|
| 160 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 161 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 162 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 163 |
+
be of type `bytes`.
|
| 164 |
+
"""
|
| 165 |
+
self._method = method
|
| 166 |
+
self._request = folders.ListFoldersRequest(request)
|
| 167 |
+
self._response = response
|
| 168 |
+
self._retry = retry
|
| 169 |
+
self._timeout = timeout
|
| 170 |
+
self._metadata = metadata
|
| 171 |
+
|
| 172 |
+
def __getattr__(self, name: str) -> Any:
|
| 173 |
+
return getattr(self._response, name)
|
| 174 |
+
|
| 175 |
+
@property
|
| 176 |
+
async def pages(self) -> AsyncIterator[folders.ListFoldersResponse]:
|
| 177 |
+
yield self._response
|
| 178 |
+
while self._response.next_page_token:
|
| 179 |
+
self._request.page_token = self._response.next_page_token
|
| 180 |
+
self._response = await self._method(
|
| 181 |
+
self._request,
|
| 182 |
+
retry=self._retry,
|
| 183 |
+
timeout=self._timeout,
|
| 184 |
+
metadata=self._metadata,
|
| 185 |
+
)
|
| 186 |
+
yield self._response
|
| 187 |
+
|
| 188 |
+
def __aiter__(self) -> AsyncIterator[folders.Folder]:
|
| 189 |
+
async def async_generator():
|
| 190 |
+
async for page in self.pages:
|
| 191 |
+
for response in page.folders:
|
| 192 |
+
yield response
|
| 193 |
+
|
| 194 |
+
return async_generator()
|
| 195 |
+
|
| 196 |
+
def __repr__(self) -> str:
|
| 197 |
+
return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
class SearchFoldersPager:
|
| 201 |
+
"""A pager for iterating through ``search_folders`` requests.
|
| 202 |
+
|
| 203 |
+
This class thinly wraps an initial
|
| 204 |
+
:class:`google.cloud.resourcemanager_v3.types.SearchFoldersResponse` object, and
|
| 205 |
+
provides an ``__iter__`` method to iterate through its
|
| 206 |
+
``folders`` field.
|
| 207 |
+
|
| 208 |
+
If there are more pages, the ``__iter__`` method will make additional
|
| 209 |
+
``SearchFolders`` requests and continue to iterate
|
| 210 |
+
through the ``folders`` field on the
|
| 211 |
+
corresponding responses.
|
| 212 |
+
|
| 213 |
+
All the usual :class:`google.cloud.resourcemanager_v3.types.SearchFoldersResponse`
|
| 214 |
+
attributes are available on the pager. If multiple requests are made, only
|
| 215 |
+
the most recent response is retained, and thus used for attribute lookup.
|
| 216 |
+
"""
|
| 217 |
+
|
| 218 |
+
def __init__(
|
| 219 |
+
self,
|
| 220 |
+
method: Callable[..., folders.SearchFoldersResponse],
|
| 221 |
+
request: folders.SearchFoldersRequest,
|
| 222 |
+
response: folders.SearchFoldersResponse,
|
| 223 |
+
*,
|
| 224 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 225 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 226 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 227 |
+
):
|
| 228 |
+
"""Instantiate the pager.
|
| 229 |
+
|
| 230 |
+
Args:
|
| 231 |
+
method (Callable): The method that was originally called, and
|
| 232 |
+
which instantiated this pager.
|
| 233 |
+
request (google.cloud.resourcemanager_v3.types.SearchFoldersRequest):
|
| 234 |
+
The initial request object.
|
| 235 |
+
response (google.cloud.resourcemanager_v3.types.SearchFoldersResponse):
|
| 236 |
+
The initial response object.
|
| 237 |
+
retry (google.api_core.retry.Retry): Designation of what errors,
|
| 238 |
+
if any, should be retried.
|
| 239 |
+
timeout (float): The timeout for this request.
|
| 240 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 241 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 242 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 243 |
+
be of type `bytes`.
|
| 244 |
+
"""
|
| 245 |
+
self._method = method
|
| 246 |
+
self._request = folders.SearchFoldersRequest(request)
|
| 247 |
+
self._response = response
|
| 248 |
+
self._retry = retry
|
| 249 |
+
self._timeout = timeout
|
| 250 |
+
self._metadata = metadata
|
| 251 |
+
|
| 252 |
+
def __getattr__(self, name: str) -> Any:
|
| 253 |
+
return getattr(self._response, name)
|
| 254 |
+
|
| 255 |
+
@property
|
| 256 |
+
def pages(self) -> Iterator[folders.SearchFoldersResponse]:
|
| 257 |
+
yield self._response
|
| 258 |
+
while self._response.next_page_token:
|
| 259 |
+
self._request.page_token = self._response.next_page_token
|
| 260 |
+
self._response = self._method(
|
| 261 |
+
self._request,
|
| 262 |
+
retry=self._retry,
|
| 263 |
+
timeout=self._timeout,
|
| 264 |
+
metadata=self._metadata,
|
| 265 |
+
)
|
| 266 |
+
yield self._response
|
| 267 |
+
|
| 268 |
+
def __iter__(self) -> Iterator[folders.Folder]:
|
| 269 |
+
for page in self.pages:
|
| 270 |
+
yield from page.folders
|
| 271 |
+
|
| 272 |
+
def __repr__(self) -> str:
|
| 273 |
+
return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
class SearchFoldersAsyncPager:
|
| 277 |
+
"""A pager for iterating through ``search_folders`` requests.
|
| 278 |
+
|
| 279 |
+
This class thinly wraps an initial
|
| 280 |
+
:class:`google.cloud.resourcemanager_v3.types.SearchFoldersResponse` object, and
|
| 281 |
+
provides an ``__aiter__`` method to iterate through its
|
| 282 |
+
``folders`` field.
|
| 283 |
+
|
| 284 |
+
If there are more pages, the ``__aiter__`` method will make additional
|
| 285 |
+
``SearchFolders`` requests and continue to iterate
|
| 286 |
+
through the ``folders`` field on the
|
| 287 |
+
corresponding responses.
|
| 288 |
+
|
| 289 |
+
All the usual :class:`google.cloud.resourcemanager_v3.types.SearchFoldersResponse`
|
| 290 |
+
attributes are available on the pager. If multiple requests are made, only
|
| 291 |
+
the most recent response is retained, and thus used for attribute lookup.
|
| 292 |
+
"""
|
| 293 |
+
|
| 294 |
+
def __init__(
|
| 295 |
+
self,
|
| 296 |
+
method: Callable[..., Awaitable[folders.SearchFoldersResponse]],
|
| 297 |
+
request: folders.SearchFoldersRequest,
|
| 298 |
+
response: folders.SearchFoldersResponse,
|
| 299 |
+
*,
|
| 300 |
+
retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
|
| 301 |
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
| 302 |
+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
|
| 303 |
+
):
|
| 304 |
+
"""Instantiates the pager.
|
| 305 |
+
|
| 306 |
+
Args:
|
| 307 |
+
method (Callable): The method that was originally called, and
|
| 308 |
+
which instantiated this pager.
|
| 309 |
+
request (google.cloud.resourcemanager_v3.types.SearchFoldersRequest):
|
| 310 |
+
The initial request object.
|
| 311 |
+
response (google.cloud.resourcemanager_v3.types.SearchFoldersResponse):
|
| 312 |
+
The initial response object.
|
| 313 |
+
retry (google.api_core.retry.AsyncRetry): Designation of what errors,
|
| 314 |
+
if any, should be retried.
|
| 315 |
+
timeout (float): The timeout for this request.
|
| 316 |
+
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
|
| 317 |
+
sent along with the request as metadata. Normally, each value must be of type `str`,
|
| 318 |
+
but for metadata keys ending with the suffix `-bin`, the corresponding values must
|
| 319 |
+
be of type `bytes`.
|
| 320 |
+
"""
|
| 321 |
+
self._method = method
|
| 322 |
+
self._request = folders.SearchFoldersRequest(request)
|
| 323 |
+
self._response = response
|
| 324 |
+
self._retry = retry
|
| 325 |
+
self._timeout = timeout
|
| 326 |
+
self._metadata = metadata
|
| 327 |
+
|
| 328 |
+
def __getattr__(self, name: str) -> Any:
|
| 329 |
+
return getattr(self._response, name)
|
| 330 |
+
|
| 331 |
+
@property
|
| 332 |
+
async def pages(self) -> AsyncIterator[folders.SearchFoldersResponse]:
|
| 333 |
+
yield self._response
|
| 334 |
+
while self._response.next_page_token:
|
| 335 |
+
self._request.page_token = self._response.next_page_token
|
| 336 |
+
self._response = await self._method(
|
| 337 |
+
self._request,
|
| 338 |
+
retry=self._retry,
|
| 339 |
+
timeout=self._timeout,
|
| 340 |
+
metadata=self._metadata,
|
| 341 |
+
)
|
| 342 |
+
yield self._response
|
| 343 |
+
|
| 344 |
+
def __aiter__(self) -> AsyncIterator[folders.Folder]:
|
| 345 |
+
async def async_generator():
|
| 346 |
+
async for page in self.pages:
|
| 347 |
+
for response in page.folders:
|
| 348 |
+
yield response
|
| 349 |
+
|
| 350 |
+
return async_generator()
|
| 351 |
+
|
| 352 |
+
def __repr__(self) -> str:
|
| 353 |
+
return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__init__.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2025 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
from collections import OrderedDict
|
| 17 |
+
from typing import Dict, Type
|
| 18 |
+
|
| 19 |
+
from .base import FoldersTransport
|
| 20 |
+
from .grpc import FoldersGrpcTransport
|
| 21 |
+
from .grpc_asyncio import FoldersGrpcAsyncIOTransport
|
| 22 |
+
from .rest import FoldersRestInterceptor, FoldersRestTransport
|
| 23 |
+
|
| 24 |
+
# Compile a registry of transports.
|
| 25 |
+
_transport_registry = OrderedDict() # type: Dict[str, Type[FoldersTransport]]
|
| 26 |
+
_transport_registry["grpc"] = FoldersGrpcTransport
|
| 27 |
+
_transport_registry["grpc_asyncio"] = FoldersGrpcAsyncIOTransport
|
| 28 |
+
_transport_registry["rest"] = FoldersRestTransport
|
| 29 |
+
|
| 30 |
+
__all__ = (
|
| 31 |
+
"FoldersTransport",
|
| 32 |
+
"FoldersGrpcTransport",
|
| 33 |
+
"FoldersGrpcAsyncIOTransport",
|
| 34 |
+
"FoldersRestTransport",
|
| 35 |
+
"FoldersRestInterceptor",
|
| 36 |
+
)
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (758 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/base.cpython-312.pyc
ADDED
|
Binary file (14 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/grpc.cpython-312.pyc
ADDED
|
Binary file (34.8 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/grpc_asyncio.cpython-312.pyc
ADDED
|
Binary file (38.9 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/__pycache__/rest.cpython-312.pyc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9310202a19f991dbc2c9b043fdf9fdc8de631aa0e819cf3a7dee0901d22e22fa
|
| 3 |
+
size 109912
|