Add ability to cancel builds that are in the waiting state
This commit is contained in:
		
							parent
							
								
									ae8bb5fc13
								
							
						
					
					
						commit
						81ce4c771e
					
				
					 8 changed files with 489 additions and 257 deletions
				
			
		|  | @ -9,7 +9,7 @@ from app import app, userfiles as user_files, build_logs, log_archive | |||
| from endpoints.api import (RepositoryParamResource, parse_args, query_param, nickname, resource, | ||||
|                            require_repo_read, require_repo_write, validate_json_request, | ||||
|                            ApiResource, internal_only, format_date, api, Unauthorized, NotFound, | ||||
|                            path_param) | ||||
|                            path_param, InvalidRequest, require_repo_admin) | ||||
| from endpoints.common import start_build | ||||
| from endpoints.trigger import BuildTrigger | ||||
| from data import model, database | ||||
|  | @ -207,6 +207,31 @@ class RepositoryBuildList(RepositoryParamResource): | |||
|     return resp, 201, headers | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| @resource('/v1/repository/<repopath:repository>/build/<build_uuid>') | ||||
| @path_param('repository', 'The full path of the repository. e.g. namespace/name') | ||||
| @path_param('build_uuid', 'The UUID of the build') | ||||
| class RepositoryBuildResource(RepositoryParamResource): | ||||
|   """ Resource for dealing with repository builds. """ | ||||
|   @require_repo_admin | ||||
|   @nickname('cancelRepoBuild') | ||||
|   def delete(self, namespace, repository, build_uuid): | ||||
|     """ Cancels a repository build if it has not yet been picked up by a build worker. """ | ||||
|     try: | ||||
|       build = model.get_repository_build(build_uuid) | ||||
|     except model.InvalidRepositoryBuildException: | ||||
|       raise NotFound() | ||||
| 
 | ||||
|     if build.repository.name != repository or build.repository.namespace_user.username != namespace: | ||||
|       raise NotFound() | ||||
| 
 | ||||
|     if model.cancel_repository_build(build): | ||||
|       return 'Okay', 201 | ||||
|     else: | ||||
|       raise InvalidRequest('Build is currently running or has finished') | ||||
| 
 | ||||
| 
 | ||||
| @resource('/v1/repository/<repopath:repository>/build/<build_uuid>/status') | ||||
| @path_param('repository', 'The full path of the repository. e.g. namespace/name') | ||||
| @path_param('build_uuid', 'The UUID of the build') | ||||
|  |  | |||
		Reference in a new issue