Skip to content

Commit

Permalink
Merge pull request #7 from dr1rrb/dev/dr/net9
Browse files Browse the repository at this point in the history
chore: Complete update to net 9
  • Loading branch information
dr1rrb authored Dec 24, 2024
2 parents b535e76 + 10ad935 commit 8a001f7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*.cs]
# CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = suggestion

# CA1812: Avoid uninstantiated internal classes
dotnet_diagnostic.CA1812.severity = suggestion

# CA2007: Do not directly await a Task ==> Irrelevant for function project
dotnet_diagnostic.CA2007.severity = none
6 changes: 3 additions & 3 deletions Crawler/DuplicatiCrawler/Client/AzureDevOps/AzureDevOpsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal sealed class AzureDevOpsApi(string auth) : IDisposable

public async Task<Dictionary<string, VariableGroup>> GetBuildVariables(CancellationToken ct)
{
var response = await _client.GetFromJsonAsync<GetVariableGroupsResponse>("distributedtask/variablegroups?api-version=5.0-preview.1", ct)
var response = await _client.GetFromJsonAsync<GetVariableGroupsResponse>(new Uri("distributedtask/variablegroups?api-version=5.0-preview.1", UriKind.Relative), ct)
?? throw new InvalidOperationException("Failed to get build variables.");

return response.Groups.ToDictionary(g => g.Name.TrimStart("duplicati-", StringComparison.OrdinalIgnoreCase));
Expand All @@ -32,7 +32,7 @@ public async Task<Dictionary<string, VariableGroup>> GetBuildVariables(Cancellat
public async Task UpdateBuildVariables(VariableGroup group, CancellationToken ct)
{
using var body = JsonContent.Create(group);
using var response = await _client.PutAsync($"distributedtask/variablegroups/{group.Id}?api-version=5.0-preview.1", body, ct);
using var response = await _client.PutAsync(new Uri($"distributedtask/variablegroups/{group.Id}?api-version=5.0-preview.1", UriKind.Relative), body, ct);
response.EnsureSuccessStatusCode();
}

Expand All @@ -44,7 +44,7 @@ public async Task QueueBuild(string channel, CancellationToken ct)
};

using var body = JsonContent.Create(new QueueBuildRequest(new BuildDefinition(1), JsonSerializer.Serialize(parameters)));
using var response = await _client.PostAsync("build/builds?api-version=5.0", body, ct);
using var response = await _client.PostAsync(new Uri("build/builds?api-version=5.0", UriKind.Relative), body, ct);
response.EnsureSuccessStatusCode();
}

Expand Down
13 changes: 9 additions & 4 deletions Crawler/DuplicatiCrawler/Client/HealthChecks/HealthchecksApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

namespace Crawler.Client.HealthChecks;

internal sealed class HealthchecksApi(IConfiguration config, ILogger<HealthchecksApi> log) : IDisposable
internal sealed partial class HealthchecksApi(IConfiguration config, ILogger<HealthchecksApi> log) : IDisposable
{
#region Logs
[LoggerMessage(0, LogLevel.Error, "Failed to ping healthchecks.io")]
private static partial void LogHealthcheckError(ILogger logger, Exception exception);
#endregion

private readonly HttpClient _client = new()
{
BaseAddress = new Uri("https://hc-ping.com/")
Expand All @@ -28,16 +33,16 @@ private async Task ReportCore(string identifier, string method, CancellationToke
return;
}

using var response = await _client.GetAsync(check + method, ct);
using var response = await _client.GetAsync(new Uri(check + method, UriKind.Relative), ct);
response.EnsureSuccessStatusCode();
}
catch (Exception e)
{
log.LogError(e, "Failed to ping healthchecks.io");
LogHealthcheckError(log, e);
}
}

/// <inheritdoc />
public void Dispose()
=> _client.Dispose();
}
}
1 change: 0 additions & 1 deletion Crawler/DuplicatiCrawler/DuplicatiCrawler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<Nullable>Enable</Nullable>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);CA2007;CA2234;CA1056;CA1063;CA1812;CA1031;CA1848;CA1816;CA2254</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
Expand Down
20 changes: 14 additions & 6 deletions Crawler/DuplicatiCrawler/ReleaseCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,35 @@

namespace Crawler;

internal sealed class ReleaseCrawler(HealthchecksApi hc, GitHubApi gitHub, AzureDevOpsApi azure, ILogger<ReleaseCrawler> log)
internal sealed partial class ReleaseCrawler(HealthchecksApi hc, GitHubApi gitHub, AzureDevOpsApi azure, ILogger<ReleaseCrawler> log)
{
#if DEBUG
private static readonly string[] _channels = ["canary"];
#else
private static readonly string[] _channels = ["stable", "beta", "experimental", "canary"];
#endif

#region Logs
[LoggerMessage(0, LogLevel.Information, "Launching crawler ({Date})")]
private static partial void LogLaunchingCrawler(ILogger logger, DateTime date);

[LoggerMessage(1, LogLevel.Error, "Failed to crawl releases.")]
private static partial void LogErrorCrawlReleases(ILogger logger, Exception exception);
#endregion

[Function("ScheduledCrawl")]
public async Task RunScheduledCrawl(
[TimerTrigger("0 0 3 * * *")] TimerInfo myTimer,
CancellationToken ct)
{
log.LogInformation($"Launching crawler ({DateTime.Now})");
LogLaunchingCrawler(log, DateTime.Now);
try
{
await CrawlReleases(_channels, ct);
}
catch (Exception e)
{
log.LogError(e, "Failed to crawl releases.");
LogErrorCrawlReleases(log, e);
}
}

Expand All @@ -50,7 +58,7 @@ public async Task<IActionResult> RunImmediateCrawl(
}
catch (Exception e)
{
log.LogError(e, "Failed to crawl releases.");
LogErrorCrawlReleases(log, e);

throw;
}
Expand Down Expand Up @@ -113,7 +121,7 @@ async Task<UpdateResult> TryUpdateChannel(string channel)
.With("version", version)
.With("url", release.data.Url)
.With("notes", release.data.Notes);

await azure.UpdateBuildVariables(@default, ct);

status = "queuing new **default** build";
Expand Down Expand Up @@ -146,4 +154,4 @@ async Task<UpdateResult> TryUpdateChannel(string channel)
}
}
}
}
}

0 comments on commit 8a001f7

Please sign in to comment.