add rate limiting to build queues

This commit is contained in:
Jimmy Zelinskie 2016-12-05 16:07:00 -05:00
parent f0b19b26c9
commit 7877c6ab94
6 changed files with 36 additions and 8 deletions

View file

@ -11,10 +11,22 @@ from endpoints.notificationhelper import spawn_notification
from util.names import escape_tag
from util.morecollections import AttrDict
logger = logging.getLogger(__name__)
MAX_BUILD_QUEUE_SIZE = app.config.get('MAX_BUILD_QUEUE_SIZE', -1)
class MaximumBuildsQueuedException(Exception):
pass
def start_build(repository, prepared_build, pull_robot_name=None):
queue_item_prefix = '%s/%s' % repository.namespace_user.username, repository.name
available_builds = dockerfile_build_queue.num_available_jobs(queue_item_prefix)
if available_builds >= MAX_BUILD_QUEUE_SIZE and MAX_BUILD_QUEUE_SIZE > -1:
raise MaximumBuildsQueuedException()
host = app.config['SERVER_HOSTNAME']
repo_path = '%s/%s/%s' % (host, repository.namespace_user.username, repository.name)