diff --git a/src/SIL.Machine.AspNetCore/Services/ServalTranslationEngineServiceV1.cs b/src/SIL.Machine.AspNetCore/Services/ServalTranslationEngineServiceV1.cs index e93474509..8fbcdee20 100644 --- a/src/SIL.Machine.AspNetCore/Services/ServalTranslationEngineServiceV1.cs +++ b/src/SIL.Machine.AspNetCore/Services/ServalTranslationEngineServiceV1.cs @@ -77,7 +77,14 @@ public override async Task StartBuild(StartBuildRequest request, ServerCa { ITranslationEngineService engineService = GetEngineService(request.EngineType); Models.Corpus[] corpora = request.Corpora.Select(Map).ToArray(); - await engineService.StartBuildAsync(request.EngineId, request.BuildId, corpora, context.CancellationToken); + try + { + await engineService.StartBuildAsync(request.EngineId, request.BuildId, corpora, context.CancellationToken); + } + catch (InvalidOperationException e) + { + throw new RpcException(new Status(StatusCode.Aborted, e.Message)); + } return Empty; } diff --git a/src/SIL.Machine.AspNetCore/Services/TranslationEngineServiceBase.cs b/src/SIL.Machine.AspNetCore/Services/TranslationEngineServiceBase.cs index 62bf488a4..4280b6c3a 100644 --- a/src/SIL.Machine.AspNetCore/Services/TranslationEngineServiceBase.cs +++ b/src/SIL.Machine.AspNetCore/Services/TranslationEngineServiceBase.cs @@ -122,19 +122,12 @@ CancellationToken cancellationToken // If there is a pending job, then no need to start a new one. if ( await Engines.ExistsAsync( - e => e.EngineId == engineId && e.BuildState == BuildState.Pending, + e => + e.EngineId == engineId && (e.BuildState == BuildState.Pending || e.BuildState == BuildState.Active), cancellationToken ) ) - return; - - // cancel the existing build before starting a new build - string? curBuildId = await CancelBuildInternalAsync(engineId, cancellationToken); - if (curBuildId is not null) - { - if (!await WaitForBuildToFinishAsync(engineId, curBuildId, CancellationToken.None)) - throw new InvalidOperationException("Unable to cancel current build."); - } + throw new InvalidOperationException("Engine is already building or pending."); // Schedule the job to occur way in the future, just so we can get the job id. string jobId = _jobClient.Schedule(GetJobExpression(engineId, buildId, corpora), TimeSpan.FromDays(10000));