Skip to content

Commit

Permalink
More broken stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Sep 23, 2024
1 parent 06b1173 commit 01ec825
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 117 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[FeatureGate("Assessment")]
public class AssessmentEnginesController(
IAuthorizationService authService,
IEngineService engineService,
IAssessmentEngineService engineService,
IJobService jobService,
IResultService resultService,
IOptionsMonitor<ApiOptions> apiOptions,
Expand All @@ -16,7 +16,7 @@ IUrlService urlService
private static readonly JsonSerializerOptions ObjectJsonSerializerOptions =
new() { Converters = { new ObjectToInferredTypesConverter() } };

private readonly IEngineService _engineService = engineService;
private readonly IAssessmentEngineService _engineService = engineService;
private readonly IJobService _jobService = jobService;
private readonly IResultService _resultService = resultService;
private readonly IOptionsMonitor<ApiOptions> _apiOptions = apiOptions;
Expand Down Expand Up @@ -64,7 +64,7 @@ public async Task<ActionResult<AssessmentEngineDto>> GetAsync(
CancellationToken cancellationToken
)
{
Engine engine = await _engineService.GetAsync(id, cancellationToken);
AssessmentEngine engine = await _engineService.GetAsync(id, cancellationToken);
await AuthorizeAsync(engine);
return Ok(Map(engine));
}
Expand Down Expand Up @@ -92,8 +92,8 @@ public async Task<ActionResult<AssessmentEngineDto>> CreateAsync(
CancellationToken cancellationToken
)
{
Engine engine = await MapAsync(getDataFileClient, engineConfig, cancellationToken);
Engine updatedEngine = await _engineService.CreateAsync(engine, cancellationToken);
AssessmentEngine engine = await MapAsync(getDataFileClient, engineConfig, cancellationToken);
AssessmentEngine updatedEngine = await _engineService.CreateAsync(engine, cancellationToken);
AssessmentEngineDto dto = Map(updatedEngine);
return Created(dto.Url, dto);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task<ActionResult<AssessmentCorpusDto>> GetCorpusAsync(
CancellationToken cancellationToken
)
{
Engine engine = await _engineService.GetAsync(id, cancellationToken);
AssessmentEngine engine = await _engineService.GetAsync(id, cancellationToken);
await AuthorizeAsync(engine);
return Ok(Map(id, Endpoints.GetAssessmentCorpus, engine.Corpus));
}
Expand Down Expand Up @@ -205,7 +205,7 @@ public async Task<ActionResult<AssessmentCorpusDto>> GetReferenceCorpusAsync(
CancellationToken cancellationToken
)
{
Engine engine = await _engineService.GetAsync(id, cancellationToken);
AssessmentEngine engine = await _engineService.GetAsync(id, cancellationToken);
await AuthorizeAsync(engine);
if (engine.ReferenceCorpus is null)
return NoContent();
Expand Down Expand Up @@ -311,7 +311,7 @@ CancellationToken cancellationToken
await AuthorizeAsync(id, cancellationToken);
if (minRevision != null)
{
(_, EntityChange<Job> change) = await TaskEx.Timeout(
(_, EntityChange<AssessmentJob> change) = await TaskEx.Timeout(
ct => _jobService.GetNewerRevisionAsync(jobId, minRevision.Value, ct),
_apiOptions.CurrentValue.LongPollTimeout,
cancellationToken: cancellationToken
Expand All @@ -325,7 +325,7 @@ CancellationToken cancellationToken
}
else
{
Job job = await _jobService.GetAsync(jobId, cancellationToken);
AssessmentJob job = await _jobService.GetAsync(jobId, cancellationToken);
return Ok(Map(job));
}
}
Expand Down Expand Up @@ -356,9 +356,9 @@ public async Task<ActionResult<AssessmentJobDto>> StartJobAsync(
CancellationToken cancellationToken
)
{
Engine engine = await _engineService.GetAsync(id, cancellationToken);
AssessmentEngine engine = await _engineService.GetAsync(id, cancellationToken);
await AuthorizeAsync(engine);
Job job = Map(engine, jobConfig);
AssessmentJob job = Map(engine, jobConfig);
await _engineService.StartJobAsync(job, cancellationToken);

AssessmentJobDto dto = Map(job);
Expand Down Expand Up @@ -499,11 +499,11 @@ CancellationToken cancellationToken

private async Task AuthorizeAsync(string id, CancellationToken cancellationToken)
{
Engine engine = await _engineService.GetAsync(id, cancellationToken);
AssessmentEngine engine = await _engineService.GetAsync(id, cancellationToken);
await AuthorizeAsync(engine);
}

private AssessmentEngineDto Map(Engine source)
private AssessmentEngineDto Map(AssessmentEngine source)
{
return new AssessmentEngineDto
{
Expand All @@ -518,13 +518,13 @@ private AssessmentEngineDto Map(Engine source)
};
}

private async Task<Engine> MapAsync(
private async Task<AssessmentEngine> MapAsync(
IRequestClient<GetDataFile> getDataFileClient,
AssessmentEngineConfigDto source,
CancellationToken cancellationToken
)
{
return new Engine
return new AssessmentEngine
{
Name = source.Name,
Type = source.Type.ToPascalCase(),
Expand All @@ -547,7 +547,7 @@ private static AssessmentResultDto Map(Result source)
};
}

private AssessmentJobDto Map(Job source)
private AssessmentJobDto Map(AssessmentJob source)
{
return new AssessmentJobDto
{
Expand All @@ -570,12 +570,12 @@ private AssessmentJobDto Map(Job source)
};
}

private static Job Map(Engine engine, AssessmentJobConfigDto source)
private static AssessmentJob Map(AssessmentEngine engine, AssessmentJobConfigDto source)
{
if (source.TextIds is not null && source.ScriptureRange is not null)
throw new InvalidOperationException("Set at most one of TextIds and ScriptureRange.");

return new Job
return new AssessmentJob
{
EngineRef = engine.Id,
Name = source.Name,
Expand Down
9 changes: 0 additions & 9 deletions src/Serval/src/Serval.Assessment/Models/AssessmentJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

public record AssessmentJob : Job
{
public string Id { get; set; } = "";
public int Revision { get; set; } = 1;
public string? Name { get; init; }
public required string EngineRef { get; init; }
public IReadOnlyList<string>? TextIds { get; set; }
public string? ScriptureRange { get; set; }
public double? PercentCompleted { get; init; }
public string? Message { get; init; }
public JobState State { get; init; } = JobState.Pending;
public DateTime? DateFinished { get; init; }
public IReadOnlyDictionary<string, object>? Options { get; init; }
}
33 changes: 18 additions & 15 deletions src/Serval/src/Serval.Assessment/Services/EngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
namespace Serval.Assessment.Services;

public class EngineService(
IRepository<Engine> engines,
IRepository<Job> jobs,
IRepository<AssessmentEngine> engines,
IRepository<AssessmentJob> jobs,
IRepository<Result> results,
GrpcClientFactory grpcClientFactory,
IOptionsMonitor<DataFileOptions> dataFileOptions,
IDataAccessContext dataAccessContext,
ILoggerFactory loggerFactory,
IScriptureDataFileService scriptureDataFileService
) : OwnedEntityServiceBase<Engine>(engines), IEngineService
) : OwnedEntityServiceBase<AssessmentEngine>(engines), IAssessmentEngineService

Check failure on line 14 in src/Serval/src/Serval.Assessment/Services/EngineService.cs

View workflow job for this annotation

GitHub Actions / Build

'EngineService' does not implement interface member 'IEngineService<AssessmentEngine, AssessmentJob>.CancelJobAsync(string, CancellationToken)'

Check failure on line 14 in src/Serval/src/Serval.Assessment/Services/EngineService.cs

View workflow job for this annotation

GitHub Actions / Build

'EngineService' does not implement interface member 'IEngineService<AssessmentEngine, AssessmentJob>.GetQueueAsync(string, CancellationToken)'
{
private readonly IRepository<Job> _jobs = jobs;
private readonly IRepository<AssessmentJob> _jobs = jobs;
private readonly IRepository<Result> _results = results;
private readonly GrpcClientFactory _grpcClientFactory = grpcClientFactory;
private readonly IOptionsMonitor<DataFileOptions> _dataFileOptions = dataFileOptions;
private readonly IDataAccessContext _dataAccessContext = dataAccessContext;
private readonly ILogger<EngineService> _logger = loggerFactory.CreateLogger<EngineService>();
private readonly IScriptureDataFileService _scriptureDataFileService = scriptureDataFileService;

public override async Task<Engine> CreateAsync(Engine engine, CancellationToken cancellationToken = default)
public override async Task<AssessmentEngine> CreateAsync(
AssessmentEngine engine,
CancellationToken cancellationToken = default
)
{
try
{
Expand All @@ -44,9 +47,9 @@ public override async Task<Engine> CreateAsync(Engine engine, CancellationToken

public override async Task DeleteAsync(string id, CancellationToken cancellationToken = default)
{
Engine? engine = await Entities.GetAsync(id, cancellationToken);
AssessmentEngine? engine = await Entities.GetAsync(id, cancellationToken);
if (engine is null)
throw new EntityNotFoundException($"Could not find the Engine '{id}'.");
throw new EntityNotFoundException($"Could not find the AssessmentEngine '{id}'.");

var client = _grpcClientFactory.CreateClient<AssessmentEngineApi.AssessmentEngineApiClient>(engine.Type);
await client.DeleteAsync(
Expand All @@ -71,7 +74,7 @@ await _dataAccessContext.WithTransactionAsync(
CancellationToken cancellationToken = default
)
{
Engine? engine = await Entities.UpdateAsync(
AssessmentEngine? engine = await Entities.UpdateAsync(
id,
u => u.Set(e => e.Corpus, corpus),
cancellationToken: cancellationToken
Expand All @@ -87,7 +90,7 @@ await _dataAccessContext.WithTransactionAsync(
CancellationToken cancellationToken = default
)
{
Engine? engine = await Entities.UpdateAsync(
AssessmentEngine? engine = await Entities.UpdateAsync(
id,
u => u.Set(e => e.ReferenceCorpus, referenceCorpus),
cancellationToken: cancellationToken
Expand All @@ -97,9 +100,9 @@ await _dataAccessContext.WithTransactionAsync(
return engine.ReferenceCorpus!;
}

public async Task StartJobAsync(Job job, CancellationToken cancellationToken = default)
public async Task StartJobAsync(AssessmentJob job, CancellationToken cancellationToken = default)
{
Engine engine = await GetAsync(job.EngineRef, cancellationToken);
AssessmentEngine engine = await GetAsync(job.EngineRef, cancellationToken);
await _jobs.InsertAsync(job, cancellationToken);

try
Expand Down Expand Up @@ -182,9 +185,9 @@ public async Task StartJobAsync(Job job, CancellationToken cancellationToken = d

public async Task<bool> CancelJobAsync(string id, string jobId, CancellationToken cancellationToken = default)
{
Engine? engine = await GetAsync(id, cancellationToken);
AssessmentEngine? engine = await GetAsync(id, cancellationToken);
if (engine is null)
throw new EntityNotFoundException($"Could not find the Engine '{id}'.");
throw new EntityNotFoundException($"Could not find the AssessmentEngine '{id}'.");

AssessmentEngineApi.AssessmentEngineApiClient client =
_grpcClientFactory.CreateClient<AssessmentEngineApi.AssessmentEngineApiClient>(engine.Type);
Expand Down Expand Up @@ -222,12 +225,12 @@ public Task DeleteAllCorpusFilesAsync(string dataFileId, CancellationToken cance
);
}

private V1.Corpus Map(Models.Corpus source)
private V1.Corpus Map(Shared.Models.Corpus source)
{
return new V1.Corpus { Language = source.Language, Files = { source.Files.Select(Map) } };
}

private V1.CorpusFile Map(Models.CorpusFile source)
private V1.CorpusFile Map(Shared.Models.CorpusFile source)
{
return new V1.CorpusFile
{
Expand Down
11 changes: 1 addition & 10 deletions src/Serval/src/Serval.Assessment/Services/IEngineService.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
namespace Serval.Assessment.Services;

public interface IEngineService
public interface IAssessmentEngineService : IEngineService<AssessmentEngine, AssessmentJob>
{
Task<IEnumerable<Engine>> GetAllAsync(string owner, CancellationToken cancellationToken = default);
Task<Engine> GetAsync(string id, CancellationToken cancellationToken = default);

Task<Engine> CreateAsync(Engine engine, CancellationToken cancellationToken = default);
Task DeleteAsync(string id, CancellationToken cancellationToken = default);

Task<Corpus> ReplaceCorpusAsync(string id, Corpus corpus, CancellationToken cancellationToken = default);
Task<Corpus> ReplaceReferenceCorpusAsync(
string id,
Corpus referenceCorpus,
CancellationToken cancellationToken = default
);

Task StartJobAsync(Job job, CancellationToken cancellationToken = default);
Task<bool> CancelJobAsync(string id, string jobId, CancellationToken cancellationToken = default);

Task DeleteAllCorpusFilesAsync(string dataFileId, CancellationToken cancellationToken = default);
}
13 changes: 0 additions & 13 deletions src/Serval/src/Serval.Assessment/Services/IJobService.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/Serval/src/Serval.Assessment/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
global using Microsoft.FeatureManagement.Mvc;
global using NSwag.Annotations;
global using Serval.Assessment.Configuration;
global using Serval.Assessment.Consumers;
global using Serval.Assessment.Contracts;
global using Serval.Assessment.Models;
global using Serval.Assessment.Services;
Expand Down
11 changes: 11 additions & 0 deletions src/Serval/src/Serval.Shared/Consumers/DataFileDeletedConsumer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Serval.Shared.Consumers;

public class DataFileDeletedConsumer<TJob>(ITrainingEngineService<TJob> engineService) : IConsumer<DataFileDeleted>
{
private readonly ITrainingEngineService<TJob> _engineService = engineService;

public async Task Consume(ConsumeContext<DataFileDeleted> context)
{
await _engineService.DeleteAllCorpusFilesAsync(context.Message.DataFileId, context.CancellationToken);
}
}
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Shared/Serval.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PackageReference Include="Grpc.HealthCheck" Version="2.65.0" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.65.0" />
<PackageReference Include="SIL.Machine" Version="3.2.6" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
<PackageReference Include="MassTransit" Version="8.0.14" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.5.0" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Shared/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
global using System.Text.Json.Serialization;
global using Grpc.Core;
global using Grpc.Net.ClientFactory;
global using MassTransit;
global using Microsoft.AspNetCore.Authorization;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
Expand Down

This file was deleted.

Loading

0 comments on commit 01ec825

Please sign in to comment.