Add support for the remaining events to the frontend and the backend
This commit is contained in:
parent
f7c154abb5
commit
af31bde997
7 changed files with 269 additions and 40 deletions
|
@ -9,7 +9,7 @@ from flask.ext.principal import identity_changed
|
|||
from random import SystemRandom
|
||||
|
||||
from data import model
|
||||
from app import app, login_manager, dockerfile_build_queue
|
||||
from app import app, login_manager, dockerfile_build_queue, notification_queue
|
||||
from auth.permissions import QuayDeferredPermissionUser
|
||||
from auth import scopes
|
||||
from endpoints.api.discovery import swagger_route_data
|
||||
|
@ -21,6 +21,7 @@ from external_libraries import get_external_javascript, get_external_css
|
|||
import features
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
profile = logging.getLogger('application.profiler')
|
||||
|
||||
route_data = None
|
||||
|
||||
|
@ -207,6 +208,7 @@ def start_build(repository, dockerfile_id, tags, build_name, subdir, manual,
|
|||
'pull_credentials': model.get_pull_credentials(pull_robot_name) if pull_robot_name else None
|
||||
}), retries_remaining=1)
|
||||
|
||||
# Add the build to the repo's log.
|
||||
metadata = {
|
||||
'repo': repository.name,
|
||||
'namespace': repository.namespace,
|
||||
|
@ -223,4 +225,47 @@ def start_build(repository, dockerfile_id, tags, build_name, subdir, manual,
|
|||
ip=request.remote_addr, metadata=metadata,
|
||||
repository=repository)
|
||||
|
||||
# Add notifications for the build queue.
|
||||
profile.debug('Adding notifications for repository')
|
||||
event_data = {
|
||||
'build_id': build_request.uuid,
|
||||
'build_name': build_name,
|
||||
'docker_tags': tags,
|
||||
'is_manual': manual,
|
||||
'trigger_id': trigger.uuid,
|
||||
'trigger_kind': trigger.service.name
|
||||
}
|
||||
|
||||
spawn_notification(repository, 'build_queued', event_data,
|
||||
subpage='build?current=' % build_request.uuid,
|
||||
pathargs=['build', build_request.uuid])
|
||||
return build_request
|
||||
|
||||
|
||||
def spawn_notification(repository, event_name, extra_data={}, subpage=None, pathargs=[]):
|
||||
homepage = 'https://quay.io/repository/%s' % repo_string
|
||||
if subpage:
|
||||
homepage = homepage + subpage
|
||||
|
||||
repo_string = '%s/%s' % (repo.namespace, repo.name)
|
||||
event_data = {
|
||||
'repository': repo_string,
|
||||
'namespace': repo.namespace,
|
||||
'name': repo.name,
|
||||
'docker_url': 'quay.io/%s' % repo_string,
|
||||
'homepage': homepage,
|
||||
'visibility': repo.visibility.name
|
||||
}
|
||||
|
||||
event_data.update(extra_data)
|
||||
|
||||
notifications = model.list_repo_notifications(repo.namespace, repo.name, event_name=event_name)
|
||||
for notification in notifications:
|
||||
notification_data = {
|
||||
'notification_id': notification.id,
|
||||
'repository_id': repository.id,
|
||||
'event_data': event_data
|
||||
}
|
||||
|
||||
path = [namespace, repository, 'notification', event_name] + pathargs
|
||||
notification_queue.put(path, json.dumps(notification_data))
|
||||
|
|
Reference in a new issue