@@ -63,6 +63,7 @@ def __init__(self, return_type=None):
6363 self ._raw_return_type = return_type
6464 self ._stop = False
6565 self ._api_client = client .ApiClient ()
66+ self .resource_version = 0
6667
6768 def stop (self ):
6869 self ._stop = True
@@ -81,16 +82,16 @@ def unmarshal_event(self, data, return_type):
8182 if return_type :
8283 obj = SimpleNamespace (data = json .dumps (js ['raw_object' ]))
8384 js ['object' ] = self ._api_client .deserialize (obj , return_type )
85+ if hasattr (js ['object' ], 'metadata' ):
86+ self .resource_version = js ['object' ].metadata .resource_version
8487 return js
8588
86- def stream (self , func , keep = False , * args , ** kwargs ):
89+ def stream (self , func , * args , ** kwargs ):
8790 """Watch an API resource and stream the result back via a generator.
8891
8992 :param func: The API function pointer. Any parameter to the function
9093 can be passed after this parameter.
9194
92- :param keep: Flag to keep the watch work all the time.
93-
9495 :return: Event object with these keys:
9596 'type': The type of event such as "ADDED", "DELETED", etc.
9697 'raw_object': a dict representing the watched object.
@@ -116,6 +117,7 @@ def stream(self, func, keep=False, *args, **kwargs):
116117 kwargs ['watch' ] = True
117118 kwargs ['_preload_content' ] = False
118119
120+ timeouts = ('timeout_seconds' in kwargs )
119121 while True :
120122 resp = func (* args , ** kwargs )
121123 try :
@@ -124,8 +126,9 @@ def stream(self, func, keep=False, *args, **kwargs):
124126 if self ._stop :
125127 break
126128 finally :
129+ kwargs ['resource_version' ] = self .resource_version
127130 resp .close ()
128131 resp .release_conn ()
129132
130- if not keep or self ._stop :
133+ if timeouts or self ._stop :
131134 break
0 commit comments