Skip to content

Commit

Permalink
Fixes sillsdev/serval#95 --ECL
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Sep 5, 2023
1 parent 3ff25ee commit 275f362
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ public override async Task<Empty> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 275f362

Please sign in to comment.