[ARVADOS] created: 5e33262f1aad92582215e29b875411d514846269
git at public.curoverse.com
git at public.curoverse.com
Thu Jul 23 11:22:18 EDT 2015
at 5e33262f1aad92582215e29b875411d514846269 (commit)
commit 5e33262f1aad92582215e29b875411d514846269
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Thu Jul 23 11:22:32 2015 -0400
6705: Use EventMachine::next_tick (which always pushes task into work queue)
instead of EventMachine::schedule (which calls recursively). Also lower limit
of number of rows to fetch at a time.
diff --git a/services/api/lib/eventbus.rb b/services/api/lib/eventbus.rb
index 35671d6..ff74ba8 100644
--- a/services/api/lib/eventbus.rb
+++ b/services/api/lib/eventbus.rb
@@ -116,7 +116,7 @@ class EventBus
# Execute query and actually send the matching log rows
count = 0
- limit = 20
+ limit = 10
logs.limit(limit).each do |l|
ws.send(l.as_api_response.to_json)
@@ -128,7 +128,7 @@ class EventBus
# Number of rows returned was capped by limit(), we need to schedule
# another query to get more logs (will start from last_log_id
# reported by current query)
- EventMachine::schedule do
+ EventMachine::next_tick do
push_events ws, nil
end
elsif !notify_id.nil? and (ws.last_log_id.nil? or notify_id > ws.last_log_id)
commit 119d87107846d77274fdaa52dc8cdadd2a7b9765
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Thu Jul 23 11:21:04 2015 -0400
6705: PollClient checks if there are more items and sends another query
immediately instead of waiting. Better error reporting from events.py on
failure to connect to websockets.
diff --git a/sdk/python/arvados/events.py b/sdk/python/arvados/events.py
index e319be3..965db2f 100644
--- a/sdk/python/arvados/events.py
+++ b/sdk/python/arvados/events.py
@@ -81,14 +81,18 @@ class PollClient(threading.Thread):
while not self.stop.isSet():
max_id = self.id
+ moreitems = False
for f in self.filters:
- items = self.api.logs().list(order="id asc", filters=f+[["id", ">", str(self.id)]]).execute()['items']
- for i in items:
+ items = self.api.logs().list(order="id asc", filters=f+[["id", ">", str(self.id)]]).execute()
+ for i in items["items"]:
if i['id'] > max_id:
max_id = i['id']
self.on_event(i)
+ if items["items_available"] > len(items["items"]):
+ moreitems = True
self.id = max_id
- self.stop.wait(self.poll_time)
+ if not moreitems:
+ self.stop.wait(self.poll_time)
def run_forever(self):
# Have to poll here, otherwise KeyboardInterrupt will never get processed.
@@ -119,16 +123,21 @@ def _subscribe_websocket(api, filters, on_event, last_log_id=None):
if not endpoint:
raise errors.FeatureNotEnabledError(
"Server does not advertise a websocket endpoint")
- uri_with_token = "{}?api_token={}".format(endpoint, api.api_token)
- client = EventClient(uri_with_token, filters, on_event, last_log_id)
- ok = False
try:
- client.connect()
- ok = True
- return client
- finally:
- if not ok:
- client.close_connection()
+ uri_with_token = "{}?api_token={}".format(endpoint, api.api_token)
+ client = EventClient(uri_with_token, filters, on_event, last_log_id)
+ ok = False
+ try:
+ client.connect()
+ ok = True
+ return client
+ finally:
+ if not ok:
+ client.close_connection()
+ except:
+ _logger.warn("Failed to connect to websockets on %s" % endpoint)
+ raise
+
def subscribe(api, filters, on_event, poll_fallback=15, last_log_id=None):
"""
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list