build queue rate limiting: address PR comments
This commit is contained in:
parent
eb69abff8b
commit
c41de8ded6
4 changed files with 12 additions and 7 deletions
|
@ -16,23 +16,27 @@ from util.morecollections import AttrDict
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MAX_BUILD_QUEUE_ITEMS = app.config.get('MAX_BUILD_QUEUE_ITEMS', -1)
|
||||
MAX_BUILD_QUEUE_SECS = app.config.get('MAX_BUILD_QUEUE_SECS', -1)
|
||||
MAX_BUILD_QUEUE_RATE_ITEMS = app.config.get('MAX_BUILD_QUEUE_RATE_ITEMS', -1)
|
||||
MAX_BUILD_QUEUE_RATE_SECS = app.config.get('MAX_BUILD_QUEUE_RATE_SECS', -1)
|
||||
|
||||
|
||||
class MaximumBuildsQueuedException(Exception):
|
||||
"""
|
||||
This exception is raised when a build is requested, but the incoming build
|
||||
would exceed the configured maximum build rate.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def start_build(repository, prepared_build, pull_robot_name=None):
|
||||
queue_item_prefix = '%s/%s' % (repository.namespace_user.username, repository.name)
|
||||
if MAX_BUILD_QUEUE_ITEMS > 0 and MAX_BUILD_QUEUE_SECS > 0:
|
||||
if MAX_BUILD_QUEUE_RATE_ITEMS > 0 and MAX_BUILD_QUEUE_RATE_SECS > 0:
|
||||
now = datetime.utcnow()
|
||||
available_min = now - timedelta(seconds=MAX_BUILD_QUEUE_SECS)
|
||||
available_min = now - timedelta(seconds=MAX_BUILD_QUEUE_RATE_SECS)
|
||||
available_builds = dockerfile_build_queue.num_available_jobs_between(available_min,
|
||||
now,
|
||||
queue_item_prefix)
|
||||
if available_builds > MAX_BUILD_QUEUE_ITEMS:
|
||||
if available_builds >= MAX_BUILD_QUEUE_RATE_ITEMS:
|
||||
raise MaximumBuildsQueuedException()
|
||||
|
||||
host = app.config['SERVER_HOSTNAME']
|
||||
|
|
Reference in a new issue