Beispiel #1
0
 async def create_topic(self,
                        topic: str,
                        partitions: int,
                        replication: int,
                        *,
                        config: Mapping[str, Any] = None,
                        timeout: Seconds = 20.0,
                        retention: Seconds = None,
                        compacting: bool = None,
                        deleting: bool = None,
                        ensure_created: bool = False) -> None:
     """Create/declare topic on server."""
     _retention = (int(want_seconds(retention) * 1000.0)
                   if retention else None)
     producer = self._ensure_producer()
     await cast(Transport, self.transport)._create_topic(
         self,
         producer.client,
         topic,
         partitions,
         replication,
         config=config,
         timeout=int(want_seconds(timeout) * 1000.0),
         retention=_retention,
         compacting=compacting,
         deleting=deleting,
         ensure_created=ensure_created,
     )
Beispiel #2
0
 async def create_topic(self,
                        topic: str,
                        partitions: int,
                        replication: int,
                        *,
                        config: Mapping[str, Any] = None,
                        timeout: Seconds = 30.0,
                        retention: Seconds = None,
                        compacting: bool = None,
                        deleting: bool = None,
                        ensure_created: bool = False) -> None:
     """Create/declare topic on server."""
     transport = cast(Transport, self.consumer.transport)
     _consumer = self._ensure_consumer()
     _retention = (int(want_seconds(retention) * 1000.0)
                   if retention else None)
     if len(topic) > TOPIC_LENGTH_MAX:
         raise ValueError(
             f'Topic name {topic!r} is too long (max={TOPIC_LENGTH_MAX})')
     await self.call_thread(
         transport._create_topic,
         self,
         _consumer._client,
         topic,
         partitions,
         replication,
         config=config,
         timeout=int(want_seconds(timeout) * 1000.0),
         retention=_retention,
         compacting=compacting,
         deleting=deleting,
         ensure_created=ensure_created,
     )
Beispiel #3
0
 async def create_topic(self,
                        topic: str,
                        partitions: int,
                        replication: int,
                        *,
                        config: Mapping[str, Any] = None,
                        timeout: Seconds = 30.0,
                        retention: Seconds = None,
                        compacting: bool = None,
                        deleting: bool = None,
                        ensure_created: bool = False) -> None:
     consumer = self.consumer
     transport = cast(Transport, consumer.transport)
     _consumer = self._ensure_consumer()
     await self.call_thread(
         transport._create_topic,
         consumer,
         _consumer._client,
         topic,
         partitions,
         replication,
         config=config,
         timeout=int(want_seconds(timeout) * 1000.0),
         retention=int(want_seconds(retention) * 1000.0),
         compacting=compacting,
         deleting=deleting,
         ensure_created=ensure_created,
     )
Beispiel #4
0
 async def set_view(self, key: str, view: View, response: Response,
                    timeout: Seconds) -> None:
     backend = self._view_backend(view)
     with suppress(backend.Unavailable):
         return await backend.set(
             key,
             view.response_to_bytes(response),
             want_seconds(timeout if timeout is not None else self.timeout),
         )
Beispiel #5
0
 async def periodic_update_peers(self, interval):
     """ Sends periodic keepalive message to all peers (if UPDATE_PEER_INTERVAL is set)
         and publishes the latest peer responses as peer list to websocket.
     """
     _interval = want_seconds(interval)
     async for _ in self.itertimer(_interval):
         await self._update_peers()
         peers = await self.list_peers()
         msg = {"from": self.identity, "peers": peers}
         await self._publish_ws(msg)
Beispiel #6
0
 async def create_topic(self,
                        topic: str,
                        partitions: int,
                        replication: int,
                        *,
                        config: Mapping[str, Any] = None,
                        timeout: Seconds = 30.0,
                        retention: Seconds = None,
                        compacting: bool = None,
                        deleting: bool = None,
                        ensure_created: bool = False) -> None:
     await self._thread.create_topic(
         topic,
         partitions,
         replication,
         config=config,
         timeout=int(want_seconds(timeout) * 1000.0),
         retention=int(want_seconds(retention) * 1000.0),
         compacting=compacting,
         deleting=deleting,
         ensure_created=ensure_created,
     )
Beispiel #7
0
 async def set_view(self,
                    key: str,
                    view: View,
                    response: Response,
                    timeout: Seconds = None) -> None:
     """Set cached value for HTTP view request."""
     backend = self._view_backend(view)
     _timeout = timeout if timeout is not None else self.timeout
     with suppress(backend.Unavailable):
         return await backend.set(
             key,
             view.response_to_bytes(response),
             want_seconds(_timeout) if _timeout is not None else None,
         )
Beispiel #8
0
def test_want_seconds(input, expected):
    assert want_seconds(input) == expected