You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because Watch is a streaming API, your code should handle disconnections gracefully.
71
+
48
72
To ensure continuous processing, the calling client _should_ execute the `Watch` call in a loop, sending in the last received [ZedToken] from `ChangesThrough` if the call disconnects:
49
73
50
74
```py
75
+
from authzed.api.v1 import (
76
+
Client, WatchRequest
77
+
)
78
+
from grpcutil import bearer_token_credentials
79
+
80
+
client = Client(
81
+
"localhost:50051",
82
+
bearer_token_credentials("your-token-here"),
83
+
)
84
+
85
+
last_zed_token =None
86
+
while not_canceled:
87
+
try:
88
+
watcher = client.Watch(WatchRequest(
89
+
optional_start_cursor=last_zed_token
90
+
))
91
+
for resp in watcher:
92
+
# process the update
93
+
last_zed_token = resp.changes_through
94
+
exceptException:
95
+
# log exception
96
+
continue
97
+
```
98
+
99
+
If your datastore supports checkpoints, you can also request them.
100
+
101
+
This will help keep the stream alive during periods of inactivity, which is helpful if your SpiceDB instance sits behind a proxy that terminates idle connections.
102
+
103
+
```py
104
+
from authzed.api.v1 import (
105
+
Client,
106
+
WatchRequest,
107
+
)
108
+
from authzed.api.v1.watch_service_pb2 importWATCH_KIND_INCLUDE_CHECKPOINTS
@@ -69,13 +135,32 @@ SpiceDB's [WriteRelationships] and [DeleteRelationships] APIs support an optiona
69
135
When `optional_transaction_metadata` is specified on the [WriteRelationships] or [DeleteRelationships] request, it will be stored and returned alongside the relationships in the Watch API:
0 commit comments