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 json
|
||||||
import threading
|
import threading
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import redis
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class CannotReadUserEventsException(Exception):
|
class CannotReadUserEventsException(Exception):
|
||||||
|
@ -56,7 +57,7 @@ class UserEvent(object):
|
||||||
as backed by Redis.
|
as backed by Redis.
|
||||||
"""
|
"""
|
||||||
def __init__(self, redis_config, username):
|
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
|
self._username = username
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -75,7 +76,7 @@ class UserEvent(object):
|
||||||
try:
|
try:
|
||||||
self.publish_event_data_sync(event_id, data_obj)
|
self.publish_event_data_sync(event_id, data_obj)
|
||||||
logger.debug('Published user event %s: %s', 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')
|
logger.exception('Could not publish user event')
|
||||||
|
|
||||||
thread = threading.Thread(target=conduct)
|
thread = threading.Thread(target=conduct)
|
||||||
|
@ -87,7 +88,8 @@ class UserEventListener(object):
|
||||||
Defines a helper class for subscribing to realtime user events as
|
Defines a helper class for subscribing to realtime user events as
|
||||||
backed by Redis.
|
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]
|
channels = [self._user_event_key(username, e) for e in events]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -114,8 +116,8 @@ class UserEventListener(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = json.loads(item['data'] or '{}')
|
data = json.loads(item['data'] or '{}')
|
||||||
except:
|
except ValueError:
|
||||||
pass
|
continue
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
yield event_id, data
|
yield event_id, data
|
||||||
|
|
Reference in a new issue