projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch '19597-multipart-request'
[arvados.git]
/
sdk
/
python
/
arvados
/
events.py
diff --git
a/sdk/python/arvados/events.py
b/sdk/python/arvados/events.py
index c308750f430c352327f53b13d5d46329b0ee28ed..e53e4980a86f01a595649331d020c6b87e823e6a 100644
(file)
--- a/
sdk/python/arvados/events.py
+++ b/
sdk/python/arvados/events.py
@@
-163,16
+163,17
@@
class PollClient(threading.Thread):
self._closing = threading.Event()
self._closing_lock = threading.RLock()
self._closing = threading.Event()
self._closing_lock = threading.RLock()
- def run(self):
if self.last_log_id != None:
# Caller supplied the last-seen event ID from a previous
if self.last_log_id != None:
# Caller supplied the last-seen event ID from a previous
- # connection
- skip_old_events = [["id", ">", str(self.last_log_id)]]
+ # connection
.
+ s
elf._s
kip_old_events = [["id", ">", str(self.last_log_id)]]
else:
# We need to do a reverse-order query to find the most
else:
# We need to do a reverse-order query to find the most
- # recent event ID (see "if not skip_old_events" below).
- skip_old_events = False
+ # recent event ID (see "if not self._skip_old_events"
+ # in run()).
+ self._skip_old_events = False
+ def run(self):
self.on_event({'status': 200})
while not self._closing.is_set():
self.on_event({'status': 200})
while not self._closing.is_set():
@@
-180,7
+181,7
@@
class PollClient(threading.Thread):
for f in self.filters:
for tries_left in RetryLoop(num_retries=25, backoff_start=.1, max_wait=self.poll_time):
try:
for f in self.filters:
for tries_left in RetryLoop(num_retries=25, backoff_start=.1, max_wait=self.poll_time):
try:
- if not skip_old_events:
+ if not s
elf._s
kip_old_events:
# If the caller didn't provide a known
# recent ID, our first request will ask
# for the single most recent event from
# If the caller didn't provide a known
# recent ID, our first request will ask
# for the single most recent event from
@@
-198,7
+199,11
@@
class PollClient(threading.Thread):
# filter on that same cutoff time, or
# (once we see our first matching event)
# the ID of the last-seen event.
# filter on that same cutoff time, or
# (once we see our first matching event)
# the ID of the last-seen event.
- skip_old_events = [[
+ #
+ # Note: self._skip_old_events must not be
+ # set until the threshold is decided.
+ # Otherwise, tests will be unreliable.
+ filter_by_time = [[
"created_at", ">=",
time.strftime(
"%Y-%m-%dT%H:%M:%SZ",
"created_at", ">=",
time.strftime(
"%Y-%m-%dT%H:%M:%SZ",
@@
-206,14
+211,19
@@
class PollClient(threading.Thread):
items = self.api.logs().list(
order="id desc",
limit=1,
items = self.api.logs().list(
order="id desc",
limit=1,
- filters=f+
skip_old_events
).execute()
+ filters=f+
filter_by_time
).execute()
if items["items"]:
if items["items"]:
- skip_old_events = [
+ s
elf._s
kip_old_events = [
["id", ">", str(items["items"][0]["id"])]]
items = {
"items": [],
"items_available": 0,
}
["id", ">", str(items["items"][0]["id"])]]
items = {
"items": [],
"items_available": 0,
}
+ else:
+ # No recent events. We can keep using
+ # the same timestamp threshold until
+ # we receive our first new event.
+ self._skip_old_events = filter_by_time
else:
# In this case, either we know the most
# recent matching ID, or we know there
else:
# In this case, either we know the most
# recent matching ID, or we know there
@@
-223,7
+233,7
@@
class PollClient(threading.Thread):
# order.
items = self.api.logs().list(
order="id asc",
# order.
items = self.api.logs().list(
order="id asc",
- filters=f+skip_old_events).execute()
+ filters=f+s
elf._s
kip_old_events).execute()
break
except errors.ApiError as error:
pass
break
except errors.ApiError as error:
pass
@@
-237,7
+247,7
@@
class PollClient(threading.Thread):
_thread.interrupt_main()
return
for i in items["items"]:
_thread.interrupt_main()
return
for i in items["items"]:
- skip_old_events = [["id", ">", str(i["id"])]]
+ s
elf._s
kip_old_events = [["id", ">", str(i["id"])]]
with self._closing_lock:
if self._closing.is_set():
return
with self._closing_lock:
if self._closing.is_set():
return