Fix the tutorial's user events
This commit is contained in:
parent
036c8e56e0
commit
094f91fb8b
3 changed files with 19 additions and 20 deletions
|
@ -1,6 +1,9 @@
|
||||||
import redis
|
import redis
|
||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class UserEventBuilder(object):
|
class UserEventBuilder(object):
|
||||||
"""
|
"""
|
||||||
|
@ -68,8 +71,9 @@ class UserEvent(object):
|
||||||
def conduct():
|
def conduct():
|
||||||
try:
|
try:
|
||||||
self.publish_event_data_sync(event_id, data_obj)
|
self.publish_event_data_sync(event_id, data_obj)
|
||||||
except Exception as e:
|
logger.debug('Published user event %s: %s', event_id, data_obj)
|
||||||
print e
|
except Exception:
|
||||||
|
logger.exception('Could not publish user event')
|
||||||
|
|
||||||
thread = threading.Thread(target=conduct)
|
thread = threading.Thread(target=conduct)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
|
@ -114,13 +114,11 @@ def create_user():
|
||||||
# Mark that the user was logged in.
|
# Mark that the user was logged in.
|
||||||
event = userevents.get_event(username)
|
event = userevents.get_event(username)
|
||||||
event.publish_event_data('docker-cli', {'action': 'login'})
|
event.publish_event_data('docker-cli', {'action': 'login'})
|
||||||
|
|
||||||
return success
|
return success
|
||||||
else:
|
else:
|
||||||
# Mark that the login failed.
|
# Mark that the login failed.
|
||||||
event = userevents.get_event(username)
|
event = userevents.get_event(username)
|
||||||
event.publish_event_data('docker-cli', {'action': 'loginfailure'})
|
event.publish_event_data('docker-cli', {'action': 'loginfailure'})
|
||||||
|
|
||||||
abort(400, error_message, issue='login-failure')
|
abort(400, error_message, issue='login-failure')
|
||||||
|
|
||||||
elif not features.USER_CREATION:
|
elif not features.USER_CREATION:
|
||||||
|
@ -231,6 +229,16 @@ def create_repository(namespace, repository):
|
||||||
repo = model.create_repository(namespace, repository,
|
repo = model.create_repository(namespace, repository,
|
||||||
get_authenticated_user())
|
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)
|
return make_response('Created', 201)
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,20 +256,6 @@ def update_images(namespace, repository):
|
||||||
# Make sure the repo actually exists.
|
# Make sure the repo actually exists.
|
||||||
abort(404, message='Unknown repository', issue='unknown-repo')
|
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')
|
logger.debug('GCing repository')
|
||||||
model.garbage_collect_repository(namespace, repository)
|
model.garbage_collect_repository(namespace, repository)
|
||||||
|
|
||||||
|
@ -272,6 +266,7 @@ def update_images(namespace, repository):
|
||||||
event_data = {
|
event_data = {
|
||||||
'updated_tags': updated_tags,
|
'updated_tags': updated_tags,
|
||||||
}
|
}
|
||||||
|
|
||||||
track_and_log('push_repo', repo)
|
track_and_log('push_repo', repo)
|
||||||
spawn_notification(repo, 'repo_push', event_data)
|
spawn_notification(repo, 'repo_push', event_data)
|
||||||
return make_response('Updated', 204)
|
return make_response('Updated', 204)
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
'templateUrl': '/static/tutorial/push-image.html',
|
'templateUrl': '/static/tutorial/push-image.html',
|
||||||
'signal': AngularTourSignals.serverEvent('/realtime/user/subscribe?events=docker-cli',
|
'signal': AngularTourSignals.serverEvent('/realtime/user/subscribe?events=docker-cli',
|
||||||
function(message, tourScope) {
|
function(message, tourScope) {
|
||||||
var pushing = message['data']['action'] == 'push_repo';
|
var pushing = message['data']['action'] == 'push_start';
|
||||||
if (pushing) {
|
if (pushing) {
|
||||||
tourScope.repoName = message['data']['repository'];
|
tourScope.repoName = message['data']['repository'];
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
'templateUrl': '/static/tutorial/pushing.html',
|
'templateUrl': '/static/tutorial/pushing.html',
|
||||||
'signal': AngularTourSignals.serverEvent('/realtime/user/subscribe?events=docker-cli',
|
'signal': AngularTourSignals.serverEvent('/realtime/user/subscribe?events=docker-cli',
|
||||||
function(message, tourScope) {
|
function(message, tourScope) {
|
||||||
return message['data']['action'] == 'pushed_repo';
|
return message['data']['action'] == 'push_repo';
|
||||||
}),
|
}),
|
||||||
'waitMessage': "Waiting for repository push to complete"
|
'waitMessage': "Waiting for repository push to complete"
|
||||||
},
|
},
|
||||||
|
|
Reference in a new issue