Skip to content

Commit

Permalink
Crash report fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Oct 15, 2023
1 parent 0213df2 commit 70fb722
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>

<DefineConstants>$(DefineConstants);BANNERLORDBUTRMODULEMANAGER_NULLABLE</DefineConstants>
</PropertyGroup>

Expand Down Expand Up @@ -78,4 +78,4 @@
<Exec Command="dotnet swagger tofile --output ../swagger.json $(OutputPath)$(AssemblyName).dll v1" />
</Target>

</Project>
</Project>
14 changes: 7 additions & 7 deletions src/BUTR.Site.NexusMods.Server/Jobs/CrashReportProcessorJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using BUTR.Site.NexusMods.Server.Options;
using BUTR.Site.NexusMods.Server.Services;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -58,7 +57,7 @@ public CrashReportProcessorJob(ILogger<CrashReportProcessorJob> logger, IService

private static async Task FilterCrashReportsAsync(TenantId tenant,
IServiceProvider serviceProvider,
IAsyncEnumerable<CrashReportFileMetadata> requests,
IEnumerable<CrashReportFileMetadata> requests,
ChannelWriter<CrashReportFileMetadata> toDownloadChannel,
ChannelWriter<CrashReportToFileIdEntity> linkedCrashReportsChannel,
ChannelWriter<CrashReportIgnoredFileEntity> ignoredCrashReportsChannel,
Expand Down Expand Up @@ -190,8 +189,8 @@ private static async Task WriteIgnoredToDatabaseAsync(
{
var dbContextFactory = serviceProvider.GetRequiredService<IAppDbContextFactory>();
var dbContextWrite = await dbContextFactory.CreateWriteAsync(ct);
await foreach (var entity in ignoredCrashReportsChannel.ReadAllAsync(ct))
dbContextWrite.CrashReportIgnoredFileIds.Add(entity);
var entries = await ignoredCrashReportsChannel.ReadAllAsync(ct).ToArrayAsync(ct);
dbContextWrite.FutureUpsert(x => x.CrashReportIgnoredFileIds, entries);
await dbContextWrite.SaveAsync(ct);
}

Expand All @@ -203,8 +202,8 @@ private static async Task WriteLinkedToDatabaseAsync(
{
var dbContextFactory = serviceProvider.GetRequiredService<IAppDbContextFactory>();
var dbContextWrite = await dbContextFactory.CreateWriteAsync(ct);
await foreach (var entity in linkedCrashReportsChannel.ReadAllAsync(ct))
dbContextWrite.CrashReportToFileIds.Add(entity);
var entries = await linkedCrashReportsChannel.ReadAllAsync(ct).ToArrayAsync(ct);
dbContextWrite.FutureUpsert(x => x.CrashReportToFileIds, entries);
await dbContextWrite.SaveAsync(ct);
}

Expand Down Expand Up @@ -305,7 +304,7 @@ static string GetException(ExceptionModel? exception, bool inner = false) => exc
// Disposing the DBContext will save the data
}

private static async Task HandleFileIdDatesAsync(TenantId tenant, IServiceProvider serviceProvider, ILogger logger, CrashReporterClient client, IAsyncEnumerable<CrashReportFileMetadata> requests, CancellationToken ct)
private static async Task HandleFileIdDatesAsync(TenantId tenant, IServiceProvider serviceProvider, ILogger logger, CrashReporterClient client, IEnumerable<CrashReportFileMetadata> requests, CancellationToken ct)
{
var options = serviceProvider.GetRequiredService<IOptions<CrashReporterOptions>>().Value;
var toDownloadChannel = Channel.CreateBounded<CrashReportFileMetadata>(ParallelCount);
Expand Down Expand Up @@ -339,6 +338,7 @@ public async Task Execute(IJobExecutionContext context)

await foreach (var batch in client.GetNewCrashReportMetadatasAsync(DateTime.UtcNow.AddHours(-2), ct).OfType<CrashReportFileMetadata>().ChunkAsync(100).WithCancellation(ct))
{
await HandleFileIdDatesAsync(tenant, scope.ServiceProvider, _logger, client, batch, ct);
processed += batch.Count;
}
}
Expand Down

0 comments on commit 70fb722

Please sign in to comment.