| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…python into pubsub
| def __init__(self, client, topic, settings, autocommit=True): | ||
| self._client = client | ||
|
|
||
| # Create a namespace that is owned by the client manager; this |
| raise Exception('Empty queue') | ||
| response = self._client.api.publish(self._.topic, self._.messages) | ||
|
|
||
| # FIXME (lukesneeringer): Check for failures; retry. |
| @@ -1,4 +1,4 @@ | |||
| # Copyright 2016 Google Inc. | |||
| Args: | ||
| message_id (str): The message ID, as a string. | ||
| """ | ||
| for callback in self._callbacks: |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| def retry(func, delay=0, count=0, err=None, **kwargs): |
| __VERSION__ = pkg_resources.get_distribution('google-cloud-pubsub').version | ||
|
|
||
|
|
||
| class SubscriberClient(subscriber_client.SubscriberClient): |
|
|
||
| __all__ = ( | ||
| 'PublisherClient', | ||
| 'SubscriberClient', |
| :class:`google.cloud.pubsub_v1.PublisherClient`. | ||
|
|
||
| Args: | ||
| client (:class:`google.cloud.pubsub_v1.PublisherClient`): The |
| inferred from this. | ||
| topic (str): The topic. The format for this is | ||
| ``projects/{project}/topics/{topic}``. | ||
| settings (:class:`google.cloud.pubsub_v1.types.Batching`): The |
| # Create a namespace that is owned by the client manager; this | ||
| # is necessary to be able to have these values be communicable between | ||
| # processes. | ||
| self._ = self.manager.Namespace() |
| self._.messages = self.manager.list() | ||
| self._.message_ids = self.manager.dict() | ||
| self._.settings = settings | ||
| self._.status = 'accepting messages' |
| Future: An object conforming to the ``concurrent.futures.Future`` | ||
| interface. | ||
| """ | ||
| # Sanity check: Is the data being sent as a bytestring? |
| return f | ||
|
|
||
|
|
||
| # Make a fake batch. This is used by the client to do single-op checks |
| def commit(self): | ||
| """Actually publish all of the messages on the active batch. | ||
|
|
||
| This moves the batch out from being the active batch to an in-flight |
| Args: | ||
| message_id (str): The message ID, as a string. | ||
| """ | ||
| for callback in self._callbacks: |
| import functools | ||
|
|
||
|
|
||
| def add_methods(SourceClass, blacklist=()): |
| :class:`google.cloud.pubsub_v1.PublisherClient`. | ||
|
|
||
| Args: | ||
| client (:class:`google.cloud.pubsub_v1.PublisherClient`): The |
| message to be published is received; subsequent messages are added to | ||
| that batch until the process of actual publishing _starts_. | ||
|
|
||
| Once this occurs, any new messages sent to ``publish`` open a new batch. |
| Future: An object conforming to the ``concurrent.futures.Future`` | ||
| interface. | ||
| """ | ||
| # Sanity check: Is the data being sent as a bytestring? |
| :class:`~gapic.pubsub.v1.publisher_client.PublisherClient`. | ||
| Generally, you should not need to set additional keyword arguments. | ||
| """ | ||
| _gapic_class = publisher_client.PublisherClient |
| """ | ||
| # If there is no matching batch yet, then potentially create one | ||
| # and place it on the batches dictionary. | ||
| if self._batches.get(topic, FAKE).status != 'accepting messages': |
|
|
||
| import queue | ||
| import uuid | ||
| import time |
Also rename base.BaseBatch to base.Batch.
There was a problem hiding this comment.
Looks mostly good, some small things and nits.
Sorry, something went wrong.
| """ | ||
| raise NotImplementedError | ||
|
|
||
| class Status(object): |
| @@ -0,0 +1,130 @@ | |||
| # Copyright 2017, Google Inc. All rights reserved. | |||
| """ | ||
| raise NotImplementedError | ||
|
|
||
| @property |
| # commit when the max latency is reached. | ||
| self._thread = None | ||
| if autocommit and self._settings.max_latency < float('inf'): | ||
| self._thread = threading.Thread(target=self.monitor) |
| version, which calls this one. | ||
| """ | ||
| # Update the status. | ||
| self._status = 'in-flight' |
| if isinstance(v, six.binary_type): | ||
| attrs[k] = v.decode('utf-8') | ||
| continue | ||
| raise TypeError('All attributes being published to Pub/Sub must ' |
| pass | ||
|
|
||
|
|
||
| class TimeoutError(GoogleAPIError): |
| return False | ||
|
|
||
| def running(self): | ||
| """Publishes in Pub/Sub currently may not be canceled. |
|
|
||
| # Wait a little while and try again. | ||
| time.sleep(_wait) | ||
| return self.exception( |
| ) | ||
|
|
||
|
|
||
| names = ['BatchSettings', 'FlowControl'] |
|
@jonparrott I think this is good other than the inner Status class that I asked about. |
Sorry, something went wrong.
|
Sorry, something went wrong.
|
Got it. GitHub obscured that and I missed it. |
Sorry, something went wrong.
|
Also, I think this knocks out everything on this PR. Is that accurate? |
Sorry, something went wrong.
|
Two outstanding items: |
Sorry, something went wrong.
|
Intentionally bypassing CircleCI because:
|
Sorry, something went wrong.
| def add_methods(source_class, blacklist=()): | ||
| """Add wrapped versions of the `api` member's methods to the class. |
There was a problem hiding this comment.
@lukesneeringer @theacodes @dhermes
Hey folks, happy 2022!
This is a long shot, as the PR is more than 4 years old, but does any of you remember what problem this decorator tried to solve? Why the generated client classes were not directly subclassed by the hand-written classes and instead kept an instance of the generated class in the .api attribute?
The thing is that type checkers issue a lot of complaints about non-existing methods, because they simply cannot know that a lot of these methods are dynamically injected at import time.
We would thus like to subclass the generated classes directly, already have a POC working, but we would like to know if there are any significant downsides to it, if anyone remembers?
Thanks!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
@jonparrott @dhermes
This is what I assert to be a mostly complete publisher for Pub/Sub (minus error checking, which is a pretty big caveat, and tests, which is also a pretty big caveat). I would like feedback on this much before I move forward, since (as we all know) multiprocessing is tricky.
I am about to add some notes inline at specific places, but obviously feel free to comment on any of it.