##// END OF EJS Templates
channelstream: nicer handle of connection errors for debug.
marcink -
r3169:c15445d5 default
parent child Browse files
Show More
@@ -26,7 +26,7 b' from pyramid.httpexceptions import HTTPB'
26 26
27 27 from rhodecode.apps._base import BaseAppView
28 28 from rhodecode.lib.channelstream import (
29 channelstream_request,
29 channelstream_request, get_channelstream_server_url,
30 30 ChannelstreamConnectionException,
31 31 ChannelstreamPermissionException,
32 32 check_channel_permissions,
@@ -56,8 +56,9 b' class ChannelstreamView(BaseAppView):'
56 56 @NotAnonymous()
57 57 @view_config(route_name='channelstream_connect', renderer='json_ext')
58 58 def connect(self):
59 """ handle authorization of users trying to connect """
60
59 61 self.load_default_context()
60 """ handle authorization of users trying to connect """
61 62 try:
62 63 json_body = self.request.json_body
63 64 except Exception:
@@ -107,11 +108,14 b' class ChannelstreamView(BaseAppView):'
107 108 'broadcast_presence_with_user_lists': True
108 109 }
109 110 # connect user to server
111 channelstream_url = get_channelstream_server_url(
112 self.channelstream_config, '/connect')
110 113 try:
111 connect_result = channelstream_request(self.channelstream_config,
112 payload, '/connect')
114 connect_result = channelstream_request(
115 self.channelstream_config, payload, '/connect')
113 116 except ChannelstreamConnectionException:
114 log.exception('Channelstream service is down')
117 log.exception(
118 'Channelstream service at {} is down'.format(channelstream_url))
115 119 return HTTPBadGateway()
116 120
117 121 connect_result['channels'] = channels
@@ -153,17 +157,21 b' class ChannelstreamView(BaseAppView):'
153 157 'store_history': True,
154 158 'broadcast_presence_with_user_lists': True
155 159 }
160
161 channelstream_url = get_channelstream_server_url(
162 self.channelstream_config, '/subscribe')
156 163 try:
157 164 connect_result = channelstream_request(
158 165 self.channelstream_config, payload, '/subscribe')
159 166 except ChannelstreamConnectionException:
160 log.exception('Channelstream service is down')
167 log.exception(
168 'Channelstream service at {} is down'.format(channelstream_url))
161 169 return HTTPBadGateway()
162 170 # include_channel_info will limit history only to new channel
163 171 # to not overwrite histories on other channels in client
164 172 connect_result['channels_info'] = parse_channels_info(
165 173 connect_result['channels_info'],
166 174 include_channel_info=filtered_channels)
167 update_history_from_logs(self.channelstream_config,
168 filtered_channels, connect_result)
175 update_history_from_logs(
176 self.channelstream_config, filtered_channels, connect_result)
169 177 return connect_result
@@ -53,23 +53,27 b' class ChannelstreamPermissionException(C'
53 53 pass
54 54
55 55
56 def get_channelstream_server_url(config, endpoint):
57 return 'http://{}{}'.format(config['server'], endpoint)
58
59
56 60 def channelstream_request(config, payload, endpoint, raise_exc=True):
57 61 signer = itsdangerous.TimestampSigner(config['secret'])
58 62 sig_for_server = signer.sign(endpoint)
59 63 secret_headers = {'x-channelstream-secret': sig_for_server,
60 64 'x-channelstream-endpoint': endpoint,
61 65 'Content-Type': 'application/json'}
62 req_url = 'http://{}{}'.format(config['server'], endpoint)
66 req_url = get_channelstream_server_url(config, endpoint)
63 67 response = None
64 68 try:
65 69 response = requests.post(req_url, data=json.dumps(payload),
66 70 headers=secret_headers).json()
67 71 except requests.ConnectionError:
68 log.exception('ConnectionError happened')
72 log.exception('ConnectionError occurred for endpoint %s', req_url)
69 73 if raise_exc:
70 raise ChannelstreamConnectionException()
74 raise ChannelstreamConnectionException(req_url)
71 75 except Exception:
72 log.exception('Exception related to channelstream happened')
76 log.exception('Exception related to Channelstream happened')
73 77 if raise_exc:
74 78 raise ChannelstreamConnectionException()
75 79 return response
General Comments 0
You need to be logged in to leave comments. Login now