Cleanup user event reporting and lower its timeout
This commit is contained in:
parent
669a3070bd
commit
3cf8f6c28a
1 changed files with 8 additions and 6 deletions
|
@ -1,8 +1,9 @@
|
|||
import redis
|
||||
import json
|
||||
import threading
|
||||
import logging
|
||||
|
||||
import redis
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class CannotReadUserEventsException(Exception):
|
||||
|
@ -56,7 +57,7 @@ class UserEvent(object):
|
|||
as backed by Redis.
|
||||
"""
|
||||
def __init__(self, redis_config, username):
|
||||
self._redis = redis.StrictRedis(socket_connect_timeout=5, **redis_config)
|
||||
self._redis = redis.StrictRedis(socket_connect_timeout=2, **redis_config)
|
||||
self._username = username
|
||||
|
||||
@staticmethod
|
||||
|
@ -75,7 +76,7 @@ class UserEvent(object):
|
|||
try:
|
||||
self.publish_event_data_sync(event_id, data_obj)
|
||||
logger.debug('Published user event %s: %s', event_id, data_obj)
|
||||
except Exception:
|
||||
except redis.RedisError:
|
||||
logger.exception('Could not publish user event')
|
||||
|
||||
thread = threading.Thread(target=conduct)
|
||||
|
@ -87,7 +88,8 @@ class UserEventListener(object):
|
|||
Defines a helper class for subscribing to realtime user events as
|
||||
backed by Redis.
|
||||
"""
|
||||
def __init__(self, redis_config, username, events=set([])):
|
||||
def __init__(self, redis_config, username, events=None):
|
||||
events = events or set([])
|
||||
channels = [self._user_event_key(username, e) for e in events]
|
||||
|
||||
try:
|
||||
|
@ -114,8 +116,8 @@ class UserEventListener(object):
|
|||
|
||||
try:
|
||||
data = json.loads(item['data'] or '{}')
|
||||
except:
|
||||
pass
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
if data:
|
||||
yield event_id, data
|
||||
|
|
Reference in a new issue