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:
yackob03 2013-11-16 15:05:26 -05:00
parent f55e4074e0
commit e787d8b2d8
4 changed files with 31 additions and 4 deletions

View file

@ -32,6 +32,7 @@ start the workers:
``` ```
STACK=prod python -m workers.diffsworker -D STACK=prod python -m workers.diffsworker -D
STACK=prod python -m workers.dockerfilebuild -D STACK=prod python -m workers.dockerfilebuild -D
STACK=prod python -m workers.webhookworker -D
``` ```
bouncing the servers: bouncing the servers:

View file

@ -56,7 +56,9 @@ class WorkQueue(object):
def complete(self, completed_item): def complete(self, completed_item):
completed_item.delete_instance() completed_item.delete_instance()
def incomplete(self, incomplete_item): def incomplete(self, incomplete_item, retry_after=300):
retry_date = datetime.now() + timedelta(seconds=retry_after)
incomplete_item.available_after = retry_date
incomplete_item.available = True incomplete_item.available = True
incomplete_item.save() incomplete_item.save()

View file

@ -6,6 +6,7 @@ from flask import request, make_response, jsonify, abort
from functools import wraps from functools import wraps
from data import model from data import model
from data.queue import webhook_queue
from app import app, mixpanel from app import app, mixpanel
from auth.auth import (process_auth, get_authenticated_user, from auth.auth import (process_auth, get_authenticated_user,
get_validated_token) get_validated_token)
@ -178,18 +179,39 @@ def update_images(namespace, repository):
permission = ModifyRepositoryPermission(namespace, repository) permission = ModifyRepositoryPermission(namespace, repository)
if permission.can(): if permission.can():
repository = model.get_repository(namespace, repository) repo = model.get_repository(namespace, repository)
if not repository: if not repo:
# Make sure the repo actually exists. # Make sure the repo actually exists.
abort(404) abort(404)
image_with_checksums = json.loads(request.data) image_with_checksums = json.loads(request.data)
updated_tags = {}
for image in image_with_checksums: for image in image_with_checksums:
logger.debug('Setting checksum for image id: %s to %s' % logger.debug('Setting checksum for image id: %s to %s' %
(image['id'], image['checksum'])) (image['id'], image['checksum']))
updated_tags[image['Tag']] = image['id']
model.set_image_checksum(image['id'], repository, image['checksum']) 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) return make_response('Updated', 204)
abort(403) abort(403)

View file

@ -2,6 +2,7 @@ import logging
import daemon import daemon
import argparse import argparse
import requests import requests
import json
from data.queue import webhook_queue from data.queue import webhook_queue
from workers.worker import Worker from workers.worker import Worker
@ -20,9 +21,10 @@ class WebhookWorker(Worker):
def process_queue_item(self, job_details): def process_queue_item(self, job_details):
url = job_details['url'] url = job_details['url']
payload = job_details['payload'] payload = job_details['payload']
headers = {'Content-type': 'application/json'}
try: try:
resp = requests.post(url, data=payload) resp = requests.post(url, data=json.dumps(payload), headers=headers)
if resp.status_code/100 != 2: if resp.status_code/100 != 2:
logger.error('%s response for webhook to url: %s' % (resp.status_code, logger.error('%s response for webhook to url: %s' % (resp.status_code,
url)) url))