Skip to content

Commit

Permalink
it builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Sep 25, 2024
1 parent 14f5047 commit c464179
Show file tree
Hide file tree
Showing 49 changed files with 388 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static IMediatorRegistrationConfigurator AddAssessmentConsumers(
this IMediatorRegistrationConfigurator configurator
)
{
configurator.AddConsumer<DataFileDeletedConsumer>();
configurator.AddConsumer<DataFileDeletedConsumer<IAssessmentEngineService>>();
return configurator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public static IMemoryDataAccessConfigurator AddAssessmentRepositories(
this IMemoryDataAccessConfigurator configurator
)
{
configurator.AddRepository<Engine>();
configurator.AddRepository<Job>();
configurator.AddRepository<AssessmentEngine>();
configurator.AddRepository<AssessmentJob>();
configurator.AddRepository<Result>();
return configurator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ public static class IMongoDataAccessConfiguratorExtensions
{
public static IMongoDataAccessConfigurator AddAssessmentRepositories(this IMongoDataAccessConfigurator configurator)
{
configurator.AddRepository<Engine>(
configurator.AddRepository<AssessmentEngine>(
"assessment.engines",
init: async c =>
{
await c.Indexes.CreateOrUpdateAsync(
new CreateIndexModel<Engine>(Builders<Engine>.IndexKeys.Ascending(e => e.Owner))
new CreateIndexModel<AssessmentEngine>(Builders<AssessmentEngine>.IndexKeys.Ascending(e => e.Owner))
);
}
);
configurator.AddRepository<Job>(
configurator.AddRepository<AssessmentJob>(
"assessment.jobs",
init: c =>
c.Indexes.CreateOrUpdateAsync(
new CreateIndexModel<Job>(Builders<Job>.IndexKeys.Ascending(b => b.EngineRef))
new CreateIndexModel<AssessmentJob>(Builders<AssessmentJob>.IndexKeys.Ascending(b => b.EngineRef))
)
);
configurator.AddRepository<Result>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static IServalBuilder AddAssessment(this IServalBuilder builder, Action<A
builder.AddDataFileOptions(builder.Configuration.GetSection(DataFileOptions.Key));
}

builder.Services.AddScoped<IJobService, JobService>();
builder.Services.AddScoped(typeof(IJobService<AssessmentJob>), typeof(JobService<AssessmentJob>));
builder.Services.AddScoped<IResultService, ResultService>();
builder.Services.AddScoped<IEngineService, EngineService>();
builder.Services.AddScoped<IAssessmentEngineService, AssessmentEngineService>();

var assessmentOptions = new AssessmentOptions();
builder.Configuration?.GetSection(AssessmentOptions.Key).Bind(assessmentOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class AssessmentEnginesController(
IAuthorizationService authService,
IAssessmentEngineService engineService,
IJobService jobService,
IJobService<AssessmentJob> jobService,
IResultService resultService,
IOptionsMonitor<ApiOptions> apiOptions,
IUrlService urlService
Expand All @@ -17,7 +17,7 @@ IUrlService urlService
new() { Converters = { new ObjectToInferredTypesConverter() } };

private readonly IAssessmentEngineService _engineService = engineService;
private readonly IJobService _jobService = jobService;
private readonly IJobService<AssessmentJob> _jobService = jobService;
private readonly IResultService _resultService = resultService;
private readonly IOptionsMonitor<ApiOptions> _apiOptions = apiOptions;
private readonly IUrlService _urlService = urlService;
Expand Down
7 changes: 6 additions & 1 deletion src/Serval/src/Serval.Assessment/Models/AssessmentEngine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace Serval.Assessment.Models;

public record AssessmentEngine : Engine
public record AssessmentEngine : IEngine
{
public string Id { get; set; } = "";
public int Revision { get; set; } = 1;
public required string Owner { get; init; }
public string? Name { get; init; }
public required string Type { get; init; }
public required Corpus Corpus { get; init; }
public Corpus? ReferenceCorpus { get; init; }
}
11 changes: 10 additions & 1 deletion src/Serval/src/Serval.Assessment/Models/AssessmentJob.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
namespace Serval.Assessment.Models;

public record AssessmentJob : Job
public record AssessmentJob : IJob
{
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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Serval.Assessment.Services;

public class EngineService(
public class AssessmentEngineService(
IRepository<AssessmentEngine> engines,
IRepository<AssessmentJob> jobs,
IRepository<Result> results,
Expand All @@ -18,7 +18,7 @@ IScriptureDataFileService scriptureDataFileService
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 ILogger<AssessmentEngineService> _logger = loggerFactory.CreateLogger<AssessmentEngineService>();
private readonly IScriptureDataFileService _scriptureDataFileService = scriptureDataFileService;

public override async Task<AssessmentEngine> CreateAsync(
Expand Down Expand Up @@ -212,7 +212,7 @@ await client.CancelJobAsync(
return true;
}

public Task DeleteAllCorpusFilesAsync(string dataFileId, CancellationToken cancellationToken = default)
public Task RemoveDataFileFromAllCorporaAsync(string dataFileId, CancellationToken cancellationToken = default)
{
return Entities.UpdateAllAsync(
e => e.Corpus.Files.Any(f => f.Id == dataFileId) || e.ReferenceCorpus!.Files.Any(f => f.Id == dataFileId),
Expand Down
26 changes: 26 additions & 0 deletions src/Serval/src/Serval.Assessment/Services/AssessmentJobService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Serval.Assessment.Services;

public class AssessmentJobService(
IDataAccessContext dataAccessContext,
IRepository<AssessmentJob> jobs,
IRepository<Result> results
) : JobService<AssessmentJob>(jobs)
{
private readonly IDataAccessContext _dataAccessContext = dataAccessContext;
private readonly IRepository<Result> _results = results;

public override Task DeleteAsync(string id, CancellationToken cancellationToken = default)
{
return _dataAccessContext.WithTransactionAsync(
async ct =>
{
IJob? job = await Entities.DeleteAsync(id, ct);
if (job is null)
throw new EntityNotFoundException($"Could not find the Job '{id}'.");
await _results.DeleteAllAsync(r => r.JobRef == id, ct);
},
cancellationToken
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace Serval.Assessment.Services;

public class AssessmentPlatformServiceV1(
IRepository<Job> jobs,
IRepository<Engine> engines,
IRepository<AssessmentJob> jobs,
IRepository<AssessmentEngine> engines,
IRepository<Result> results,
IDataAccessContext dataAccessContext,
IPublishEndpoint publishEndpoint
Expand All @@ -14,8 +14,8 @@ IPublishEndpoint publishEndpoint
private const int ResultInsertBatchSize = 128;
private static readonly Empty Empty = new();

private readonly IRepository<Job> _jobs = jobs;
private readonly IRepository<Engine> _engines = engines;
private readonly IRepository<AssessmentJob> _jobs = jobs;
private readonly IRepository<AssessmentEngine> _engines = engines;
private readonly IRepository<Result> _results = results;
private readonly IDataAccessContext _dataAccessContext = dataAccessContext;
private readonly IPublishEndpoint _publishEndpoint = publishEndpoint;
Expand All @@ -25,15 +25,15 @@ public override async Task<Empty> JobStarted(JobStartedRequest request, ServerCa
await _dataAccessContext.WithTransactionAsync(
async (ct) =>
{
Job? job = await _jobs.UpdateAsync(
AssessmentJob? job = await _jobs.UpdateAsync(
request.JobId,
u => u.Set(b => b.State, JobState.Active),
cancellationToken: ct
);
if (job is null)
throw new RpcException(new Status(StatusCode.NotFound, "The job does not exist."));
Engine? engine = await _engines.GetAsync(job.EngineRef, cancellationToken: ct);
AssessmentEngine? engine = await _engines.GetAsync(job.EngineRef, cancellationToken: ct);
if (engine is null)
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));
Expand All @@ -57,7 +57,7 @@ public override async Task<Empty> JobCompleted(JobCompletedRequest request, Serv
await _dataAccessContext.WithTransactionAsync(
async (ct) =>
{
Job? job = await _jobs.UpdateAsync(
AssessmentJob? job = await _jobs.UpdateAsync(
request.JobId,
u =>
u.Set(b => b.State, JobState.Completed)
Expand All @@ -68,7 +68,7 @@ await _dataAccessContext.WithTransactionAsync(
if (job is null)
throw new RpcException(new Status(StatusCode.NotFound, "The job does not exist."));
Engine? engine = await _engines.GetAsync(job.EngineRef, cancellationToken: ct);
AssessmentEngine? engine = await _engines.GetAsync(job.EngineRef, cancellationToken: ct);
if (engine is null)
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));
Expand Down Expand Up @@ -96,7 +96,7 @@ public override async Task<Empty> JobCanceled(JobCanceledRequest request, Server
await _dataAccessContext.WithTransactionAsync(
async (ct) =>
{
Job? job = await _jobs.UpdateAsync(
AssessmentJob? job = await _jobs.UpdateAsync(
request.JobId,
u =>
{
Expand All @@ -109,7 +109,7 @@ await _dataAccessContext.WithTransactionAsync(
if (job is null)
throw new RpcException(new Status(StatusCode.NotFound, "The job does not exist."));
Engine? engine = await _engines.GetAsync(job.EngineRef, cancellationToken: ct);
AssessmentEngine? engine = await _engines.GetAsync(job.EngineRef, cancellationToken: ct);
if (engine is null)
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));
Expand Down Expand Up @@ -137,7 +137,7 @@ public override async Task<Empty> JobFaulted(JobFaultedRequest request, ServerCa
await _dataAccessContext.WithTransactionAsync(
async (ct) =>
{
Job? job = await _jobs.UpdateAsync(
AssessmentJob? job = await _jobs.UpdateAsync(
request.JobId,
u =>
{
Expand All @@ -150,7 +150,7 @@ await _dataAccessContext.WithTransactionAsync(
if (job is null)
throw new RpcException(new Status(StatusCode.NotFound, "The job does not exist."));
Engine? engine = await _engines.GetAsync(job.EngineRef, cancellationToken: ct);
AssessmentEngine? engine = await _engines.GetAsync(job.EngineRef, cancellationToken: ct);
if (engine is null)
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));
Expand All @@ -175,7 +175,7 @@ await _publishEndpoint.Publish(

public override async Task<Empty> JobRestarting(JobRestartingRequest request, ServerCallContext context)
{
Job? job = await _jobs.UpdateAsync(
AssessmentJob? job = await _jobs.UpdateAsync(
request.JobId,
u =>
{
Expand Down Expand Up @@ -225,7 +225,7 @@ ServerCallContext context
{
if (jobId != request.JobId)
{
Job? job = await _jobs.GetAsync(request.JobId, context.CancellationToken);
AssessmentJob? job = await _jobs.GetAsync(request.JobId, context.CancellationToken);
if (job is null)
throw new RpcException(new Status(StatusCode.NotFound, "The job does not exist."));
engineId = job.EngineRef;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Serval.Assessment.Services;

public interface IAssessmentEngineService : IEngineServiceBase
{
Task<IEnumerable<AssessmentEngine>> GetAllAsync(string owner, CancellationToken cancellationToken = default);
Task<AssessmentEngine> GetAsync(string engineId, CancellationToken cancellationToken = default);

Task<AssessmentEngine> CreateAsync(AssessmentEngine engine, CancellationToken cancellationToken = default);
Task DeleteAsync(string engineId, CancellationToken cancellationToken = default);
Task StartJobAsync(AssessmentJob build, CancellationToken cancellationToken = default);
Task<bool> CancelJobAsync(string engineId, string jobId, CancellationToken cancellationToken = default);
Task<Corpus> ReplaceCorpusAsync(string id, Corpus corpus, CancellationToken cancellationToken = default);
Task<Corpus> ReplaceReferenceCorpusAsync(
string id,
Corpus referenceCorpus,
CancellationToken cancellationToken = default
);
}
13 changes: 0 additions & 13 deletions src/Serval/src/Serval.Assessment/Services/IEngineService.cs

This file was deleted.

62 changes: 0 additions & 62 deletions src/Serval/src/Serval.Assessment/Services/JobService.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Serval/src/Serval.Assessment/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
global using System.Diagnostics.CodeAnalysis;
global using System.Linq.Expressions;
global using System.Text.Json;
global using System.Text.Json.Nodes;
global using Asp.Versioning;
Expand All @@ -21,6 +20,7 @@
global using Serval.Assessment.Models;
global using Serval.Assessment.Services;
global using Serval.Shared.Configuration;
global using Serval.Shared.Consumers;
global using Serval.Shared.Contracts;
global using Serval.Shared.Controllers;
global using Serval.Shared.Models;
Expand Down
Loading

0 comments on commit c464179

Please sign in to comment.