Handle user events Redis not working in tutorial
Also does some basic restyling Fixes #1586
This commit is contained in:
		
							parent
							
								
									073b643aab
								
							
						
					
					
						commit
						310ecd11cc
					
				
					 6 changed files with 169 additions and 162 deletions
				
			
		|  | @ -5,6 +5,9 @@ import logging | |||
| 
 | ||||
| logger = logging.getLogger(__name__) | ||||
| 
 | ||||
| class CannotReadUserEventsException(Exception): | ||||
|   """ Exception raised if user events cannot be read. """ | ||||
| 
 | ||||
| class UserEventBuilder(object): | ||||
|   """ | ||||
|   Defines a helper class for constructing UserEvent and UserEventListener | ||||
|  | @ -87,9 +90,13 @@ class UserEventListener(object): | |||
|   def __init__(self, redis_config, username, events=set([])): | ||||
|     channels = [self._user_event_key(username, e) for e in events] | ||||
| 
 | ||||
|     self._redis = redis.StrictRedis(socket_connect_timeout=5, **redis_config) | ||||
|     self._pubsub = self._redis.pubsub() | ||||
|     self._pubsub.subscribe(channels) | ||||
|     try: | ||||
|       self._redis = redis.StrictRedis(socket_connect_timeout=5, **redis_config) | ||||
|       self._pubsub = self._redis.pubsub() | ||||
|       self._pubsub.subscribe(channels) | ||||
|     except redis.RedisError as re: | ||||
|       logger.exception('Could not reach user events redis: %s', re) | ||||
|       raise CannotReadUserEventsException | ||||
| 
 | ||||
|   @staticmethod | ||||
|   def _user_event_key(username, event_id): | ||||
|  |  | |||
		Reference in a new issue