@@ -290,7 +290,7 @@ def subscribe(self, queries, sharding=None, timeout: Optional[float] = None):
290290 """
291291 Subscribe creates and executes a Subscribe protobuf message,
292292 returning a stream of notificationBatch.
293- queries must be a list of querry protobuf messages.
293+ queries must be a list of query protobuf messages.
294294 sharding, if present must be a protobuf sharding message.
295295 timeout: if present, sets the GRPC timeout in seconds. Default is None (no timeout).
296296 """
@@ -302,6 +302,42 @@ def subscribe(self, queries, sharding=None, timeout: Optional[float] = None):
302302 stream = self .__client .Subscribe (req , metadata = self .metadata , timeout = timeout )
303303 return (self .decode_batch (nb ) for nb in stream )
304304
305+ def getAndSubscribe (
306+ self ,
307+ queries : List [rtr .Query ],
308+ start : Optional [TIME_TYPE ] = None ,
309+ versions = 0 ,
310+ sharding = None ,
311+ exact_range = False ,
312+ timeout : Optional [float ] = None ,
313+ ):
314+ """
315+ GetAndSubscribe creates and executes a GetAndSubscribe protobuf message,
316+ returning a stream of notificationBatch. This will initially consist of notifications
317+ of the current state in CloudVision (i.e. a Get), after which it will transition to a
318+ subscription method, where update notifications will be received for changes occurring to
319+ the queried paths.
320+ queries must be a list of query protobuf messages.
321+ start, if present, must be a google.protobuf.timestamp_pb2.Timestamp or a datetime object.
322+ versions, if present, specifies the maximum number of versions to retrieve.
323+ sharding, if present must be a protobuf sharding message.
324+ exact_range, if present, specifies whether to return the initial state at time `start`.
325+ timeout: if present, sets the GRPC timeout in seconds. Default is None (no timeout).
326+ """
327+ start_ts = 0
328+ if start :
329+ start_ts = to_pbts (start ).ToNanoseconds ()
330+
331+ request = rtr .GetAndSubscribeRequest (
332+ query = queries ,
333+ start = start_ts ,
334+ versions = versions ,
335+ sharded_sub = sharding ,
336+ exact_range = exact_range ,
337+ )
338+ stream = self .__client .GetAndSubscribe (request , metadata = self .metadata , timeout = timeout )
339+ return (self .decode_batch (nb ) for nb in stream )
340+
305341 def publish (
306342 self ,
307343 dId ,
@@ -359,6 +395,7 @@ def decode_batch(self, batch):
359395 "name" : batch .dataset .name ,
360396 "type" : batch .dataset .type ,
361397 },
398+ "metadata" : batch .metadata ,
362399 "notifications" : [self .decode_notification (n ) for n in batch .notifications ],
363400 }
364401 return res
0 commit comments