Fix handling of multi-part branches in the build triggers

Fixes #1360
This commit is contained in:
Joseph Schorr 2016-07-26 13:41:13 -07:00
parent 9d48bcd0f1
commit 06d52f2c83
7 changed files with 232 additions and 21 deletions

View file

@ -87,36 +87,44 @@ def trigger_view(trigger, can_read=False, can_admin=False, for_build=False):
return None
def build_status_view(build_obj):
def _get_build_status(build_obj):
""" Returns the updated build phase, status and (if any) error for the build object. """
phase = build_obj.phase
status = {}
error = None
try:
status = build_logs.get_status(build_obj.uuid)
except BuildStatusRetrievalError as bsre:
phase = 'cannot_load'
if SuperUserPermission().can():
error = str(bsre)
else:
error = 'Redis may be down. Please contact support.'
# If the build is currently running, then load its "real-time" status from Redis.
if not database.BUILD_PHASE.is_terminal_phase(phase):
try:
status = build_logs.get_status(build_obj.uuid)
except BuildStatusRetrievalError as bsre:
phase = 'cannot_load'
if SuperUserPermission().can():
error = str(bsre)
else:
error = 'Redis may be down. Please contact support.'
if phase != 'cannot_load':
# If the status contains a heartbeat, then check to see if has been written in the last few
# minutes. If not, then the build timed out.
if phase != database.BUILD_PHASE.COMPLETE and phase != database.BUILD_PHASE.ERROR:
if phase != 'cannot_load':
# If the status contains a heartbeat, then check to see if has been written in the last few
# minutes. If not, then the build timed out.
if status is not None and 'heartbeat' in status and status['heartbeat']:
heartbeat = datetime.datetime.utcfromtimestamp(status['heartbeat'])
if datetime.datetime.utcnow() - heartbeat > datetime.timedelta(minutes=1):
phase = database.BUILD_PHASE.INTERNAL_ERROR
# If the phase is internal error, return 'error' instead if the number of retries
# on the queue item is 0.
if phase == database.BUILD_PHASE.INTERNAL_ERROR:
retry = build_obj.queue_id and dockerfile_build_queue.has_retries_remaining(build_obj.queue_id)
if not retry:
phase = database.BUILD_PHASE.ERROR
# If the phase is internal error, return 'error' instead if the number of retries
# on the queue item is 0.
if phase == database.BUILD_PHASE.INTERNAL_ERROR:
retry = (build_obj.queue_id and
dockerfile_build_queue.has_retries_remaining(build_obj.queue_id))
if not retry:
phase = database.BUILD_PHASE.ERROR
return (phase, status, error)
def build_status_view(build_obj):
phase, status, error = _get_build_status(build_obj)
repo_namespace = build_obj.repository.namespace_user.username
repo_name = build_obj.repository.name