Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Or using the context manager, for finer control:
```python
async with restate.with_connection(app, name="greeter-v1") as connection:
print(connection.info.deployment_url)
await connection.wait()
await connection.wait_closed()
```

### Clients
Expand Down
23 changes: 19 additions & 4 deletions python/restate/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import signal
import sys
import typing
import warnings
from contextlib import asynccontextmanager

from restate.server_types import RestateAppT
Expand Down Expand Up @@ -66,20 +67,34 @@ def info(self) -> TunnelInfo:
"""Metadata from the first successful handshake (``deployment_url``, ``proxy_url``, …)."""
return self._info

async def wait(self) -> None:
async def wait_closed(self) -> None:
"""
Wait until the connection stops serving: returns after :meth:`shutdown`, raises
:class:`ConnectError` when the connection failed for good (rejected credentials,
an exhausted reconnect policy, …).
"""
await self._engine.terminated()

async def wait(self) -> None:
"""
Deprecated alias of :meth:`wait_closed`.

.. deprecated:: 1.4.0
Use :meth:`wait_closed` instead.
"""
warnings.warn(
"Connection.wait() is deprecated, use Connection.wait_closed() instead",
DeprecationWarning,
stacklevel=2,
)
await self.wait_closed()

async def shutdown(self, grace: float = 0.0) -> None:
"""
Stop serving. New invocations are refused and Restate Cloud is told; in-flight
invocations get ``grace`` seconds to finish before the connections are cut.
``0`` cuts them at once. Never raises: a connection that already failed reports
its error through :meth:`wait`, not here.
its error through :meth:`wait_closed`, not here.
"""
try:
await self._engine.shutdown(grace)
Expand Down Expand Up @@ -119,7 +134,7 @@ async def with_connection(

async with restate.with_connection(app, name="greeter") as connection:
print(connection.info.deployment_url)
await connection.wait()
await connection.wait_closed()
"""
options = TunnelEngineOptions.resolve(name=name, key=key)
engine = TunnelEngine(app, options)
Expand Down Expand Up @@ -199,4 +214,4 @@ def on_signal() -> None:
file=sys.stderr,
flush=True,
)
await connection.wait()
await connection.wait_closed()
2 changes: 1 addition & 1 deletion tests/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ async def run() -> None:
assert conn.info.name == TUNNEL_NAME
response = await cloud.request("/http/h/9080/discover", identity_headers("/discover"))
assert response.status == 200
waiter = asyncio.ensure_future(conn.wait())
waiter = asyncio.ensure_future(conn.wait_closed())
await asyncio.sleep(0.05)
assert not waiter.done()
await conn.shutdown(0.0)
Expand Down
Loading