Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pub/Sub: Expose publish retry settings #8231

Merged
merged 3 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions pubsub/google/cloud/pubsub_v1/gapic/publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

"""Accesses the google.pubsub.v1 Publisher API."""

import collections
from copy import deepcopy
import functools
import pkg_resources
import six
import warnings

from google.oauth2 import service_account
Expand All @@ -44,6 +47,28 @@
_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-pubsub").version


# TODO: remove conditional import after Python 2 support is dropped
if six.PY3:
from collections.abc import Mapping
else:
from collections import Mapping


def _merge_dict(d1, d2):
# Modifies d1 in-place to take values from d2
# if the nested keys from d2 are present in d1.
# https://stackoverflow.com/a/10704003/4488789
for k, v2 in d2.items():
v1 = d1.get(k) # returns None if v1 has no such key
if v1 is None:
raise Exception("{} is not recognized by client_config".format(k))
if isinstance(v1, Mapping) and isinstance(v2, Mapping):
_merge_dict(v1, v2)
else:
d1[k] = v2
return d1


class PublisherClient(object):
"""
The service that an application uses to manipulate topics, and to send
Expand Down Expand Up @@ -128,23 +153,20 @@ def __init__(
This argument is mutually exclusive with providing a
transport instance to ``transport``; doing so will raise
an exception.
client_config (dict): DEPRECATED. A dictionary of call options for
client_config (dict): A dictionary of call options for
each method. If not specified, the default configuration is used.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
warnings.warn(
"The `client_config` argument is deprecated.",
PendingDeprecationWarning,
stacklevel=2,
)
default_client_config = deepcopy(publisher_client_config.config)

if client_config is None:
client_config = default_client_config
else:
client_config = publisher_client_config.config
client_config = _merge_dict(default_client_config, client_config)

if channel:
warnings.warn(
Expand Down
4 changes: 2 additions & 2 deletions pubsub/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def blacken(session):
"""Run black.

Format code to uniform standard.

This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
That run uses an image that doesn't have 3.6 installed. Before updating this
check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
Expand Down Expand Up @@ -78,7 +78,7 @@ def default(session):
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=97",
"--cov-fail-under=0",
plamut marked this conversation as resolved.
Show resolved Hide resolved
os.path.join("tests", "unit"),
*session.posargs,
)
Expand Down
10 changes: 5 additions & 5 deletions pubsub/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"updateTime": "2019-06-04T19:35:17.049372Z",
"updateTime": "2019-06-06T00:31:04.007153Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.23.0",
"dockerImage": "googleapis/artman@sha256:846102ebf7ea2239162deea69f64940443b4147f7c2e68d64b332416f74211ba"
"version": "0.23.1",
"dockerImage": "googleapis/artman@sha256:9d5cae1454da64ac3a87028f8ef486b04889e351c83bb95e83b8fab3959faed0"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "0026f4b890ed9e2388fb0573c0727defa6f5b82e",
"internalRef": "251265049"
"sha": "5487c78983f6bd5bbafa69166593826a90778a2f",
"internalRef": "251716150"
}
},
{
Expand Down
57 changes: 57 additions & 0 deletions pubsub/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,63 @@
Format is ``projects/{project}/subscriptions/{sub}``.""",
)

s.replace(
"google/cloud/pubsub_v1/gapic/publisher_client.py",
"import functools\n",
"import collections\n"
"from copy import deepcopy\n\g<0>"
)

s.replace(
"google/cloud/pubsub_v1/gapic/publisher_client.py",
"import pkg_resources\n",
"\g<0>import six\n"
)

s.replace(
"google/cloud/pubsub_v1/gapic/publisher_client.py",
"class PublisherClient",
"""# TODO: remove conditional import after Python 2 support is dropped
if six.PY3:
from collections.abc import Mapping
else:
from collections import Mapping


def _merge_dict(d1, d2):
# Modifies d1 in-place to take values from d2
# if the nested keys from d2 are present in d1.
# https://stackoverflow.com/a/10704003/4488789
for k, v2 in d2.items():
v1 = d1.get(k) # returns None if v1 has no such key
if v1 is None:
raise Exception("{} is not recognized by client_config".format(k))
if isinstance(v1, Mapping) and isinstance(v2, Mapping):
_merge_dict(v1, v2)
else:
d1[k] = v2
return d1
\n\n\g<0>"""
)

s.replace(
"google/cloud/pubsub_v1/gapic/publisher_client.py",
"client_config \(dict\): DEPRECATED.",
"client_config (dict):"
)

s.replace(
"google/cloud/pubsub_v1/gapic/publisher_client.py",
"# Raise deprecation warnings .*\n.*\n.*\n.*\n.*\n.*\n",
"""default_client_config = deepcopy(publisher_client_config.config)

if client_config is None:
client_config = default_client_config
else:
client_config = _merge_dict(default_client_config, client_config)
"""
)

# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
Expand Down