Make the worker post json. Add a retry timeout after an incompletel queue item is processed. Submit webhook jobs to the queue on a successful push.
This commit is contained in:
parent
f55e4074e0
commit
e787d8b2d8
4 changed files with 31 additions and 4 deletions
|
@ -6,6 +6,7 @@ from flask import request, make_response, jsonify, abort
|
|||
from functools import wraps
|
||||
|
||||
from data import model
|
||||
from data.queue import webhook_queue
|
||||
from app import app, mixpanel
|
||||
from auth.auth import (process_auth, get_authenticated_user,
|
||||
get_validated_token)
|
||||
|
@ -178,18 +179,39 @@ def update_images(namespace, repository):
|
|||
permission = ModifyRepositoryPermission(namespace, repository)
|
||||
|
||||
if permission.can():
|
||||
repository = model.get_repository(namespace, repository)
|
||||
if not repository:
|
||||
repo = model.get_repository(namespace, repository)
|
||||
if not repo:
|
||||
# Make sure the repo actually exists.
|
||||
abort(404)
|
||||
|
||||
image_with_checksums = json.loads(request.data)
|
||||
|
||||
updated_tags = {}
|
||||
for image in image_with_checksums:
|
||||
logger.debug('Setting checksum for image id: %s to %s' %
|
||||
(image['id'], image['checksum']))
|
||||
updated_tags[image['Tag']] = image['id']
|
||||
model.set_image_checksum(image['id'], repository, image['checksum'])
|
||||
|
||||
# Generate a job for each webhook that has been added to this repo
|
||||
webhooks = model.list_webhooks(namespace, repository)
|
||||
for webhook in webhooks:
|
||||
webhook_data = json.loads(webhook.parameters)
|
||||
repo_string = '%s/%s' % (namespace, repository)
|
||||
logger.debug('Creating webhook for repository \'%s\' for url \'%s\'' %
|
||||
(repo_string, webhook_data['url']))
|
||||
webhook_data['payload'] = {
|
||||
'repository': repo_string,
|
||||
'namespace': namespace,
|
||||
'name': repository,
|
||||
'docker_url': 'quay.io/%s' % repo_string,
|
||||
'homepage': 'https://quay.io/repository/%s' % repo_string,
|
||||
'visibility': repo.visibility.name,
|
||||
'updated_tags': updated_tags,
|
||||
'pushed_image_count': len(image_with_checksums),
|
||||
}
|
||||
webhook_queue.put(json.dumps(webhook_data))
|
||||
|
||||
return make_response('Updated', 204)
|
||||
|
||||
abort(403)
|
||||
|
|
Reference in a new issue