Skip to content

Commit

Permalink
Try 2 for editor config:
Browse files Browse the repository at this point in the history
* Namespace always file level
* Always primary constructor
* Inline null checks
* Enforce naming
* Fix spelling mistakes
* simplify default initializations
* Add static and readonly where valid
* Remove unnecessary usings.
* No Functional change
* Change private static to PascalCase
* Add if multiline brackets.  Align editorconfig with serval.
* TreatWarningsAsErrors
  • Loading branch information
johnml1135 committed Feb 21, 2024
1 parent 525950f commit e064c4f
Show file tree
Hide file tree
Showing 241 changed files with 20,431 additions and 20,131 deletions.
444 changes: 444 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"recommendations": [
"ms-dotnettools.csharp",
"ms-dotnettools.csdevkit",
"streetsidesoftware.code-spell-checker",
"csharpier.csharpier-vscode",
"editorconfig.editorconfig",
"mhutchie.git-graph",
"tim-koehler.helm-intellisense",
"ms-dotnettools.vscodeintellicode-csharp",
"redhat.vscode-yaml",
"wycliffeassociates.usfmvscode"
]
}
164 changes: 163 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,170 @@
"cmake.configureOnOpen": false,
"notebook.formatOnSave.enabled": true,
"cSpell.words": [
"acceptables",
"addtl",
"allo",
"Anns",
"argmax",
"backtranslation",
"BBBCCCVVV",
"bdry",
"bestal",
"Bidir",
"bleu",
"bleus",
"Blockable",
"Bson",
"Nito"
"Cdecl",
"chapternumber",
"clearml",
"Cloneable",
"Clusterer",
"Clusterers",
"cmds",
"colspan",
"crossreference",
"crule",
"ctxt",
"decr",
"Denormalize",
"Determinizable",
"Determinize",
"Detokenize",
"Detokenizer",
"Dfst",
"Dont",
"DYNACONF",
"endmarker",
"ernfa",
"esbe",
"fert",
"firstlineindent",
"fminsearch",
"fontname",
"fontsize",
"Heapify",
"huggingface",
"invswm",
"Kneser",
"Koehn",
"Kore",
"ksmr",
"langtags",
"leftmargin",
"lexnd",
"Liang",
"linespacing",
"Lsdbc",
"ltor",
"mindfa",
"Minibatch",
"Morpher",
"morphophonemic",
"Morphosyntactic",
"mrule",
"mrules",
"msubrule",
"mult",
"nbest",
"nblist",
"nblists",
"Nelder",
"Nestless",
"Nfkc",
"Nfkd",
"Nfst",
"Ngram",
"ngrams",
"Nito",
"NLLB",
"NMLZ",
"nomon",
"nonaccepting",
"nondistinguisable",
"nonhead",
"Nonoverlapping",
"nonpublishable",
"nonvernacular",
"notetext",
"notrepeatable",
"numer",
"Nums",
"occursunder",
"optbreak",
"paratext",
"Partitioner",
"Postorder",
"Postprocess",
"Preorder",
"Preprocess",
"Pretranslate",
"pretranslation",
"Pretranslations",
"probs",
"Protobuf",
"prule",
"prules",
"pseq",
"psubrule",
"ptemp",
"pubnumber",
"Punct",
"realizational",
"redup",
"Retryable",
"rightmargin",
"rtol",
"seglen",
"segs",
"sentencepiece",
"Sents",
"Sldr",
"smallcaps",
"spaceafter",
"spacebefore",
"srcsegmlentable",
"Strs",
"stylesheet",
"styletype",
"subclassing",
"Submatches",
"Subtag",
"Subtags",
"succ",
"symmetr",
"tdata",
"testylename",
"textproperties",
"texttype",
"Thot",
"Tokenizes",
"translationnote",
"trgcutstable",
"trgsegmlentable",
"Truecase",
"Truecaser",
"ttable",
"ttrace",
"Typesafe",
"Unapplication",
"Unapply",
"unbuilt",
"underspecified",
"Unigram",
"Uninstantiated",
"unrooted",
"unsmooth",
"Untruncate",
"Upgma",
"USFM",
"versenumber",
"versetext",
"vref",
"Witten",
"Wpps",
"xmltag",
"zwsp"
],
"dotnet.defaultSolution": "Machine.sln"
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ public static IMachineBuilder AddBuildJobService(this IMachineBuilder builder, I
public static IMachineBuilder AddBuildJobService(this IMachineBuilder builder)
{
if (builder.Configuration is null)
{
builder.AddBuildJobService(o => { });
}
else
{
builder.AddBuildJobService(builder.Configuration.GetSection(BuildJobOptions.Key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public static IMachineBuilder AddMachine(this IServiceCollection services, IConf

services.AddScoped<IDistributedReaderWriterLockFactory, DistributedReaderWriterLockFactory>();
services.AddSingleton<ICorpusService, CorpusService>();
services.AddStartupTask((sp, ct) => sp.GetRequiredService<IDistributedReaderWriterLockFactory>().InitAsync(ct));
services.AddStartupTask(
(sp, cancellationToken) =>
sp.GetRequiredService<IDistributedReaderWriterLockFactory>().InitAsync(cancellationToken)
);

var builder = new MachineBuilder(services, configuration);
if (configuration is null)
Expand Down
12 changes: 3 additions & 9 deletions src/SIL.Machine.AspNetCore/Configuration/MachineBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
namespace Microsoft.Extensions.DependencyInjection;

internal class MachineBuilder : IMachineBuilder
internal class MachineBuilder(IServiceCollection services, IConfiguration? configuration) : IMachineBuilder
{
public MachineBuilder(IServiceCollection services, IConfiguration? configuration)
{
Services = services;
Configuration = configuration;
}

public IServiceCollection Services { get; }
public IConfiguration? Configuration { get; }
public IServiceCollection Services { get; } = services;
public IConfiguration? Configuration { get; } = configuration;
}
13 changes: 5 additions & 8 deletions src/SIL.Machine.AspNetCore/Models/ModelDownloadUrl.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
namespace SIL.Machine.AspNetCore.Models;

namespace SIL.Machine.AspNetCore.Models
public class ModelDownloadUrl
{
public class ModelDownloadUrl
{
public string Url { get; set; } = default!;
public int ModelRevision { get; set; } = default!;
public DateTime ExipiresAt { get; set; } = default!;
}
public string Url { get; set; } = default!;
public int ModelRevision { get; set; } = default!;
public DateTime ExpiresAt { get; set; } = default!;
}
5 changes: 4 additions & 1 deletion src/SIL.Machine.AspNetCore/SIL.Machine.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Description>An ASP.NET Core web API middleware for the Machine library.</Description>
<NoWarn>1591</NoWarn>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591;CS1573</NoWarn>
</PropertyGroup>

<Import Project="../AssemblyInfo.props" />
Expand Down
12 changes: 3 additions & 9 deletions src/SIL.Machine.AspNetCore/Services/BuildProgress.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
namespace SIL.Machine.AspNetCore.Services;

public class BuildProgress : IProgress<ProgressStatus>
public class BuildProgress(IPlatformService platformService, string buildId) : IProgress<ProgressStatus>
{
private readonly IPlatformService _platformService;
private readonly string _buildId;
private readonly IPlatformService _platformService = platformService;
private readonly string _buildId = buildId;
private ProgressStatus _prevStatus;

private DateTime _lastReportTime = DateTime.Now;

private const float ThrottleTimeSeconds = 1;

public BuildProgress(IPlatformService platformService, string buildId)
{
_platformService = platformService;
_buildId = buildId;
}

public void Report(ProgressStatus value)
{
if (_prevStatus.Equals(value))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
namespace SIL.Machine.AspNetCore.Services;

public class CancellationInterceptor : Interceptor
public class CancellationInterceptor(ILogger<CancellationInterceptor> logger) : Interceptor
{
private readonly ILogger<CancellationInterceptor> _logger;

public CancellationInterceptor(ILogger<CancellationInterceptor> logger)
{
_logger = logger;
}
private readonly ILogger<CancellationInterceptor> _logger = logger;

public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
TRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ protected override async Task DoWorkAsync(IServiceScope scope, CancellationToken
{
if (_authToken is "")
{
_logger.LogError(e, "Error occurred while aquiring ClearML authentication token for the first time.");
_logger.LogError(e, "Error occurred while acquiring ClearML authentication token for the first time.");
// The ClearML token never was set. We can't continue without it.
throw;
}
else
{
_logger.LogError(e, "Error occurred while refreshing ClearML authentication token.");
}
}
}

Expand Down
19 changes: 8 additions & 11 deletions src/SIL.Machine.AspNetCore/Services/ClearMLBuildJobRunner.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
namespace SIL.Machine.AspNetCore.Services;

public class ClearMLBuildJobRunner : IBuildJobRunner
public class ClearMLBuildJobRunner(
IClearMLService clearMLService,
IEnumerable<IClearMLBuildJobFactory> buildJobFactories
) : IBuildJobRunner
{
private readonly IClearMLService _clearMLService;
private readonly Dictionary<TranslationEngineType, IClearMLBuildJobFactory> _buildJobFactories;

public ClearMLBuildJobRunner(IClearMLService clearMLService, IEnumerable<IClearMLBuildJobFactory> buildJobFactories)
{
_clearMLService = clearMLService;
_buildJobFactories = buildJobFactories.ToDictionary(f => f.EngineType);
}
private readonly IClearMLService _clearMLService = clearMLService;
private readonly Dictionary<TranslationEngineType, IClearMLBuildJobFactory> _buildJobFactories =
buildJobFactories.ToDictionary(f => f.EngineType);

public BuildJobRunner Type => BuildJobRunner.ClearML;

Expand Down Expand Up @@ -40,8 +38,7 @@ public async Task<string> CreateJobAsync(
)
{
string? projectId = await _clearMLService.GetProjectIdAsync(engineId, cancellationToken);
if (projectId is null)
projectId = await _clearMLService.CreateProjectAsync(engineId, cancellationToken: cancellationToken);
projectId ??= await _clearMLService.CreateProjectAsync(engineId, cancellationToken: cancellationToken);

ClearMLTask? task = await _clearMLService.GetTaskByNameAsync(buildId, cancellationToken);
if (task is not null)
Expand Down
34 changes: 15 additions & 19 deletions src/SIL.Machine.AspNetCore/Services/ClearMLHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
public class ClearMLHealthCheck : IHealthCheck
{
private readonly HttpClient _httpClient;
private readonly IOptionsMonitor<ClearMLOptions> _options;
private readonly IClearMLAuthenticationService _clearMLAuthenticationService;
private int _numConsecutiveFailures;
private readonly AsyncLock _lock;
namespace SIL.Machine.AspNetCore.Services;

public ClearMLHealthCheck(
IClearMLAuthenticationService clearMLAuthenticationService,
IHttpClientFactory httpClientFactory,
IOptionsMonitor<ClearMLOptions> options
)
{
_httpClient = httpClientFactory.CreateClient("ClearML-NoRetry");
_options = options;
_clearMLAuthenticationService = clearMLAuthenticationService;
_numConsecutiveFailures = 0;
_lock = new AsyncLock();
}
public class ClearMLHealthCheck(
IClearMLAuthenticationService clearMLAuthenticationService,
IHttpClientFactory httpClientFactory,
IOptionsMonitor<ClearMLOptions> options
) : IHealthCheck
{
private readonly HttpClient _httpClient = httpClientFactory.CreateClient("ClearML-NoRetry");
private readonly IOptionsMonitor<ClearMLOptions> _options = options;
private readonly IClearMLAuthenticationService _clearMLAuthenticationService = clearMLAuthenticationService;
private int _numConsecutiveFailures = 0;
private readonly AsyncLock _lock = new AsyncLock();

public async Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context,
Expand All @@ -29,9 +22,12 @@ public async Task<HealthCheckResult> CheckHealthAsync(
if (!await PingAsync(cancellationToken))
return HealthCheckResult.Unhealthy("ClearML is unresponsive");
if (!await WorkersAreAssignedToQueue(cancellationToken))
{
return HealthCheckResult.Unhealthy(
$"No ClearML agents are available for configured queue \"{_options.CurrentValue.Queue}\""
);
}

using (await _lock.LockAsync())
_numConsecutiveFailures = 0;
return HealthCheckResult.Healthy("ClearML is available");
Expand Down
Loading

0 comments on commit e064c4f

Please sign in to comment.