public static Task <EntityChange <Build> > GetNewerRevisionAsync(this IBuildRepository repo, BuildLocatorType locatorType, string locator, long minRevision, CancellationToken ct) { switch (locatorType) { case BuildLocatorType.Id: return(repo.GetNewerRevisionAsync(locator, minRevision, ct)); case BuildLocatorType.Engine: return(repo.GetNewerRevisionByEngineIdAsync(locator, minRevision, ct)); } return(null); }
public async Task <bool> CancelBuildAsync(BuildLocatorType locatorType, string locator) { CheckDisposed(); using (await _lock.ReaderLockAsync()) { Build build = await _buildRepo.GetByLocatorAsync(locatorType, locator); if (build == null) { return(false); } if (_runners.TryGetValue(build.EngineId, out Owned <EngineRunner> runner)) { await runner.Value.CancelBuildAsync(); } return(true); } }
public static async Task <Build> GetByLocatorAsync(this IBuildRepository buildRepo, BuildLocatorType locatorType, string locator, CancellationToken ct = default(CancellationToken)) { switch (locatorType) { case BuildLocatorType.Id: return(await buildRepo.GetAsync(locator, ct)); case BuildLocatorType.Engine: return(await buildRepo.GetByEngineIdAsync(locator, ct)); } return(null); }
public static async Task <Build> GetByLocatorAsync(this IBuildRepository buildRepo, BuildLocatorType locatorType, string locator) { switch (locatorType) { case BuildLocatorType.Id: return(await buildRepo.GetAsync(locator)); case BuildLocatorType.Engine: return(await buildRepo.GetByEngineIdAsync(locator)); } return(null); }
public async Task <IActionResult> GetAsync(string locatorType, string locator, [FromQuery] long?minRevision, CancellationToken ct) { BuildLocatorType buildLocatorType = GetLocatorType(locatorType); if (minRevision != null) { string engineId = null; switch (buildLocatorType) { case BuildLocatorType.Id: Build build = await _builds.GetAsync(locator); if (build == null) { return(NotFound()); } engineId = build.EngineRef; break; case BuildLocatorType.Engine: engineId = locator; break; } Engine engine = await _engines.GetAsync(engineId); if (engine == null) { return(NotFound()); } if (!await AuthorizeAsync(engine, Operations.Read)) { return(StatusCode(StatusCodes.Status403Forbidden)); } EntityChange <Build> change = await _builds.GetNewerRevisionAsync(buildLocatorType, locator, minRevision.Value, ct).Timeout(_engineOptions.Value.BuildLongPollTimeout, ct); switch (change.Type) { case EntityChangeType.None: return(NoContent()); case EntityChangeType.Delete: return(NotFound()); default: return(Ok(CreateDto(change.Entity))); } } else { Build build = await _builds.GetByLocatorAsync(buildLocatorType, locator); if (build == null) { return(NotFound()); } Engine engine = await _engines.GetAsync(build.EngineRef); if (engine == null) { return(NotFound()); } if (!await AuthorizeAsync(engine, Operations.Read)) { return(StatusCode(StatusCodes.Status403Forbidden)); } return(Ok(CreateDto(build))); } }