@@ -168,42 +168,35 @@ def recent_blobs(self):
168
168
169
169
def _listen (self , last_object , object_type , blocking = True , interval = 15 , query = None ):
170
170
if last_object is None :
171
- last_object = next (self ._recent (object_type , query = query ))
171
+ last_object = next (self ._recent (object_type , query = query ), None )
172
172
# If there are no elements (even first element): just get new samples from now on
173
- if last_object is not None :
174
- last_id = last_object .id
175
- last_time = last_object .upload_time
176
173
elif isinstance (last_object , MWDBObject ):
177
174
# If we are requesting for typed objects, we should additionally check the object type
178
175
if object_type is not MWDBObject and not isinstance (last_object , object_type ):
179
176
raise TypeError ("latest_object type must be 'str' or '{}'" .format (object_type .__name__ ))
180
177
# If object instance provided: get ID from instance
181
- last_id = last_object .id
182
- last_time = last_object .upload_time
183
178
else :
184
179
# If not: first check whether object exists in repository
185
- last_obj = self ._query (object_type , last_object , raise_not_found = True )
186
- last_id = last_obj .id
187
- last_time = last_obj .upload_time
180
+ last_object = self ._query (object_type , last_object , raise_not_found = True )
188
181
189
182
while True :
190
183
objects = []
191
184
for obj in self ._recent (object_type , query = query ):
192
- if obj .id == last_id :
193
- break
194
-
195
- if obj .upload_time < last_time :
196
- raise RuntimeError (
197
- "Newly fetched object [{}] is older than the pivot [{}]" .format (
198
- obj .id , last_id
185
+ if last_object :
186
+ if obj .id == last_object .id :
187
+ break
188
+
189
+ if obj .upload_time < last_object .upload_time :
190
+ raise RuntimeError (
191
+ "Newly fetched object [{}] is older than the pivot [{}]" .format (
192
+ obj .id , last_object .id
193
+ )
199
194
)
200
- )
201
195
objects .append (obj )
202
196
203
197
# Return fetched objects in reversed order (from oldest to latest)
204
198
for obj in objects [::- 1 ]:
205
- last_id = obj .id
206
- last_time = obj .upload_time
199
+ last_object = obj
207
200
yield obj
208
201
if blocking :
209
202
time .sleep (interval )
0 commit comments