Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added serval release version to translation build #517

Merged
merged 10 commits into from
Nov 4, 2024
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ services:
'/bin/sh',
'-c',
'mongod --quiet --replSet myRS --bind_ip 0.0.0.0 & sleep 2s; mongosh --host localhost:27017 --eval '' config = { "_id" : "myRS", "members" : [{"_id" : 0,"host" : "mongo:27017"}] }; rs.initiate(config, { force: true }); '' ; sleep infinity'
]
]
3 changes: 3 additions & 0 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9838,6 +9838,9 @@ public partial class TranslationBuild
[Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public object? Options { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("deploymentVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? DeploymentVersion { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public record TranslationBuildDto
/// }
/// </example>
public object? Options { get; init; }
public string? DeploymentVersion { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class TranslationEnginesController(
IBuildService buildService,
IPretranslationService pretranslationService,
IOptionsMonitor<ApiOptions> apiOptions,
IConfiguration configuration,
IUrlService urlService,
ILogger<TranslationEnginesController> logger
) : ServalControllerBase(authService)
Expand All @@ -22,6 +23,7 @@ ILogger<TranslationEnginesController> logger
private readonly IOptionsMonitor<ApiOptions> _apiOptions = apiOptions;
private readonly IUrlService _urlService = urlService;
private readonly ILogger<TranslationEnginesController> _logger = logger;
private readonly IConfiguration _configuration = configuration;

/// <summary>
/// Get all translation engines
Expand Down Expand Up @@ -1046,9 +1048,12 @@ public async Task<ActionResult<TranslationBuildDto>> StartBuildAsync(
CancellationToken cancellationToken
)
{
string deploymentVersion = _configuration.GetValue<string>("deploymentVersion") ?? "Unknown";

Engine engine = await _engineService.GetAsync(id, cancellationToken);
await AuthorizeAsync(engine);
Build build = Map(engine, buildConfig);
Build build = Map(engine, buildConfig, deploymentVersion);

await _engineService.StartBuildAsync(build, cancellationToken);

TranslationBuildDto dto = Map(build);
Expand Down Expand Up @@ -1311,15 +1316,16 @@ private Engine Map(TranslationEngineConfigDto source)
};
}

private static Build Map(Engine engine, TranslationBuildConfigDto source)
private static Build Map(Engine engine, TranslationBuildConfigDto source, string deploymentVersion)
{
return new Build
{
EngineRef = engine.Id,
Name = source.Name,
Pretranslate = Map(engine, source.Pretranslate),
TrainOn = Map(engine, source.TrainOn),
Options = Map(source.Options)
Options = Map(source.Options),
DeploymentVersion = deploymentVersion
};
}

Expand Down Expand Up @@ -1534,7 +1540,8 @@ private TranslationBuildDto Map(Build source)
QueueDepth = source.QueueDepth,
State = source.State,
DateFinished = source.DateFinished,
Options = source.Options
Options = source.Options,
DeploymentVersion = source.DeploymentVersion
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Translation/Models/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public record Build : IEntity
public JobState State { get; init; } = JobState.Pending;
public DateTime? DateFinished { get; init; }
public IReadOnlyDictionary<string, object>? Options { get; init; }
public string? DeploymentVersion { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,9 @@ public async Task StartBuildForEngineByIdAsync(IEnumerable<string> scope, int ex

build = await client.GetCurrentBuildAsync(engineId);
Assert.That(build, Is.Not.Null);

Assert.That(build.DeploymentVersion, Is.Not.Null);

break;
case 400:
case 403:
Expand Down
Loading