Toward running quay in a docker container.
This commit is contained in:
parent
6e2b8d96b8
commit
8e9faf6121
11 changed files with 138 additions and 38 deletions
|
@ -33,13 +33,38 @@ class SendToMixpanel(Process):
|
|||
self._consumer.send(*json.loads(mp_request))
|
||||
|
||||
|
||||
def init_app(app):
|
||||
logger.debug('Initializing mixpanel with key: %s' %
|
||||
app.config['MIXPANEL_KEY'])
|
||||
class FakeMixpanel(object):
|
||||
def track(*args, **kwargs):
|
||||
pass
|
||||
|
||||
request_queue = Queue()
|
||||
mixpanel = Mixpanel(app.config['MIXPANEL_KEY'],
|
||||
MixpanelQueingConsumer(request_queue))
|
||||
SendToMixpanel(request_queue).start()
|
||||
|
||||
return mixpanel
|
||||
class Analytics(object):
|
||||
def __init__(self, app=None):
|
||||
self.app = app
|
||||
if app is not None:
|
||||
self.state = self.init_app(app)
|
||||
else:
|
||||
self.state = None
|
||||
|
||||
def init_app(self, app):
|
||||
analytics_type = app.config.get('ANALYTICS_TYPE', 'FakeAnalytics')
|
||||
|
||||
if analytics_type == 'Mixpanel':
|
||||
mixpanel_key = app.config.get('MIXPANEL_KEY', '')
|
||||
logger.debug('Initializing mixpanel with key: %s' %
|
||||
app.config['MIXPANEL_KEY'])
|
||||
|
||||
request_queue = Queue()
|
||||
analytics = Mixpanel(mixpanel_key, MixpanelQueingConsumer(request_queue))
|
||||
SendToMixpanel(request_queue).start()
|
||||
|
||||
else:
|
||||
analytics = FakeMixpanel()
|
||||
|
||||
# register extension with app
|
||||
app.extensions = getattr(app, 'extensions', {})
|
||||
app.extensions['analytics'] = analytics
|
||||
return analytics
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.state, name, None)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
import json
|
||||
|
||||
from app import mixpanel
|
||||
from app import analytics
|
||||
from flask import request, abort as flask_abort, make_response, current_app
|
||||
from auth.auth_context import get_authenticated_user, get_validated_token
|
||||
|
||||
|
@ -32,10 +32,10 @@ def abort(status_code, message=None, issue=None, headers=None, **kwargs):
|
|||
auth_user = get_authenticated_user()
|
||||
auth_token = get_validated_token()
|
||||
if auth_user:
|
||||
mixpanel.track(auth_user.username, 'http_error', params)
|
||||
analytics.track(auth_user.username, 'http_error', params)
|
||||
message = '%s (user: %s)' % (message, auth_user.username)
|
||||
elif auth_token:
|
||||
mixpanel.track(auth_token.code, 'http_error', params)
|
||||
analytics.track(auth_token.code, 'http_error', params)
|
||||
message = '%s (token: %s)' % (message,
|
||||
auth_token.friendly_name or auth_token.code)
|
||||
|
||||
|
|
Reference in a new issue