From 094f91fb8b544bf08cb34a9ca1880cb8e2d35adb Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 3 Apr 2015 12:13:33 -0400 Subject: [PATCH] Fix the tutorial's user events --- data/userevent.py | 8 ++++++-- endpoints/index.py | 27 +++++++++++---------------- static/js/pages/tutorial.js | 4 ++-- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/data/userevent.py b/data/userevent.py index 5523da2e5..aea34226a 100644 --- a/data/userevent.py +++ b/data/userevent.py @@ -1,6 +1,9 @@ import redis import json import threading +import logging + +logger = logging.getLogger(__name__) class UserEventBuilder(object): """ @@ -68,8 +71,9 @@ class UserEvent(object): def conduct(): try: self.publish_event_data_sync(event_id, data_obj) - except Exception as e: - print e + logger.debug('Published user event %s: %s', event_id, data_obj) + except Exception: + logger.exception('Could not publish user event') thread = threading.Thread(target=conduct) thread.start() diff --git a/endpoints/index.py b/endpoints/index.py index e42696777..79e7c9041 100644 --- a/endpoints/index.py +++ b/endpoints/index.py @@ -114,13 +114,11 @@ def create_user(): # Mark that the user was logged in. event = userevents.get_event(username) event.publish_event_data('docker-cli', {'action': 'login'}) - return success else: # Mark that the login failed. event = userevents.get_event(username) event.publish_event_data('docker-cli', {'action': 'loginfailure'}) - abort(400, error_message, issue='login-failure') elif not features.USER_CREATION: @@ -231,6 +229,16 @@ def create_repository(namespace, repository): repo = model.create_repository(namespace, repository, get_authenticated_user()) + if get_authenticated_user(): + user_event_data = { + 'action': 'push_start', + 'repository': repository, + 'namespace': namespace + } + + event = userevents.get_event(get_authenticated_user().username) + event.publish_event_data('docker-cli', user_event_data) + return make_response('Created', 201) @@ -248,20 +256,6 @@ def update_images(namespace, repository): # Make sure the repo actually exists. abort(404, message='Unknown repository', issue='unknown-repo') - if get_authenticated_user(): - logger.debug('Publishing push event') - username = get_authenticated_user().username - - # Mark that the user has pushed the repo. - user_data = { - 'action': 'pushed_repo', - 'repository': repository, - 'namespace': namespace - } - - event = userevents.get_event(username) - event.publish_event_data('docker-cli', user_data) - logger.debug('GCing repository') model.garbage_collect_repository(namespace, repository) @@ -272,6 +266,7 @@ def update_images(namespace, repository): event_data = { 'updated_tags': updated_tags, } + track_and_log('push_repo', repo) spawn_notification(repo, 'repo_push', event_data) return make_response('Updated', 204) diff --git a/static/js/pages/tutorial.js b/static/js/pages/tutorial.js index d5661c73b..3f0c18cf3 100644 --- a/static/js/pages/tutorial.js +++ b/static/js/pages/tutorial.js @@ -59,7 +59,7 @@ 'templateUrl': '/static/tutorial/push-image.html', 'signal': AngularTourSignals.serverEvent('/realtime/user/subscribe?events=docker-cli', function(message, tourScope) { - var pushing = message['data']['action'] == 'push_repo'; + var pushing = message['data']['action'] == 'push_start'; if (pushing) { tourScope.repoName = message['data']['repository']; } @@ -73,7 +73,7 @@ 'templateUrl': '/static/tutorial/pushing.html', 'signal': AngularTourSignals.serverEvent('/realtime/user/subscribe?events=docker-cli', function(message, tourScope) { - return message['data']['action'] == 'pushed_repo'; + return message['data']['action'] == 'push_repo'; }), 'waitMessage': "Waiting for repository push to complete" },