Adding in UI for cancel anytime.

This commit is contained in:
Charlton Austin 2016-11-16 13:51:07 -05:00
parent f6fe9023a4
commit 2fe74e4057
11 changed files with 31 additions and 25 deletions

View file

@ -13,6 +13,7 @@ PRESUMED_DEAD_BUILD_AGE = timedelta(days=15)
PHASES_NOT_ALLOWED_TO_CANCEL_FROM = (BUILD_PHASE.PUSHING, BUILD_PHASE.COMPLETE,
BUILD_PHASE.ERROR, BUILD_PHASE.INTERNAL_ERROR)
ARCHIVABLE_BUILD_PHASES = [BUILD_PHASE.COMPLETE, BUILD_PHASE.ERROR, BUILD_PHASE.CANCELLED]
def update_build_trigger(trigger, config, auth_token=None):
trigger.config = json.dumps(config or {})
@ -184,19 +185,11 @@ def create_cancel_build_in_queue(build, build_queue):
def create_cancel_build_in_manager(build, build_canceller):
""" A function to cancel the build before it starts to push """
def cancel_build():
original_phase = build.phase
if build.phase in PHASES_NOT_ALLOWED_TO_CANCEL_FROM:
return False
build.phase = BUILD_PHASE.CANCELLED
build.save()
return build_canceller.try_cancel_build(build.uuid)
if not build_canceller.try_cancel_build(build.uuid):
build.phase = original_phase
build.save()
return False
return True
return cancel_build
@ -213,22 +206,23 @@ def cancel_repository_build(build, build_queue):
cancel_builds = [create_cancel_build_in_queue(build, build_queue),
create_cancel_build_in_manager(build, build_canceller), ]
original_phase = build.phase
for cancelled in cancel_builds:
if cancelled():
# Delete the build row.
# TODO Charlie 2016-11-11 Add in message that says build was cancelled and remove the delete build.
build.delete_instance()
build.phase = BUILD_PHASE.CANCELLED
build.save()
return True
build.phase = original_phase
build.save()
return False
def get_archivable_build():
presumed_dead_date = datetime.utcnow() - PRESUMED_DEAD_BUILD_AGE
candidates = (RepositoryBuild
.select(RepositoryBuild.id)
.where((RepositoryBuild.phase == BUILD_PHASE.COMPLETE) |
(RepositoryBuild.phase == BUILD_PHASE.ERROR) |
.where((RepositoryBuild.phase << ARCHIVABLE_BUILD_PHASES) |
(RepositoryBuild.started < presumed_dead_date),
RepositoryBuild.logs_archived == False)
.limit(50)