Moves the six backend projects on disk into Core/ and Hosts/ subfolders, matching the solution folders already defined in Musify.slnx, so the file explorer reflects the same layout as the solution: backend/Core/Musify.Domain backend/Core/Musify.Application backend/Core/Musify.Infrastructure backend/Hosts/Musify.Api backend/Hosts/Musify.Worker backend/Hosts/Musify.StreamingGateway Updates every reference to the old paths: ProjectReference entries in Musify.Api.csproj and Musify.Worker.csproj, the three Dockerfiles, deploy/scripts/migrate.ps1|sh, deploy/zitadel/provision.ps1, deploy/up.ps1, deploy/README.md and docs/development.md. Also fixes a stale Dockerfile comment pointing at a compose file that no longer exists. Verified with `dotnet build Musify.slnx` against the new layout.
75 lines
2.9 KiB
C#
75 lines
2.9 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Musify.Application.Configuration;
|
|
using Musify.Domain.ValueObjects;
|
|
using Musify.Application.Contracts;
|
|
|
|
namespace Musify.Infrastructure.Jobs
|
|
{
|
|
public class UploadIntentExpirationJob(
|
|
IServiceScopeFactory scopeFactory,
|
|
ILogger<UploadIntentExpirationJob> logger,
|
|
UploadIntentConfiguration uploadIntentConfiguration)
|
|
: BackgroundService
|
|
{
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
logger.LogInformation("UploadIntentExpirationJob started (interval: {Interval}s)", uploadIntentConfiguration.ExpirationJobIntervalSeconds);
|
|
|
|
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(uploadIntentConfiguration.ExpirationJobIntervalSeconds));
|
|
|
|
do
|
|
{
|
|
try
|
|
{
|
|
await RunAsync(stoppingToken);
|
|
}
|
|
catch (Exception exception) when (exception is not OperationCanceledException)
|
|
{
|
|
logger.LogError(exception, "Error in UploadIntentExpirationJob");
|
|
}
|
|
}
|
|
while (await timer.WaitForNextTickAsync(stoppingToken));
|
|
}
|
|
|
|
async Task RunAsync(CancellationToken cancellationToken)
|
|
{
|
|
await using var scope = scopeFactory.CreateAsyncScope();
|
|
var database = scope.ServiceProvider.GetRequiredService<IDatabase>();
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
var expiredIntents = await database.UploadIntents
|
|
.Where(i => i.Status == UploadIntentStatus.Issued && i.ExpiresAt < now)
|
|
.ToListAsync(cancellationToken);
|
|
|
|
if (expiredIntents.Count > 0)
|
|
{
|
|
foreach (var intent in expiredIntents)
|
|
intent.Status = UploadIntentStatus.Expired;
|
|
|
|
await database.SaveChangesAsync(cancellationToken);
|
|
logger.LogInformation("Marked {Count} upload intents as Expired", expiredIntents.Count);
|
|
}
|
|
|
|
if (uploadIntentConfiguration.ExpiredIntentsRetentionDays >= 0)
|
|
{
|
|
var retentionCutoff = now.AddDays(-uploadIntentConfiguration.ExpiredIntentsRetentionDays);
|
|
|
|
var oldExpiredIntents = await database.UploadIntents
|
|
.Where(i => i.Status == UploadIntentStatus.Expired && i.ExpiresAt < retentionCutoff)
|
|
.ToListAsync(cancellationToken);
|
|
|
|
if (oldExpiredIntents.Count > 0)
|
|
{
|
|
database.UploadIntents.RemoveRange(oldExpiredIntents);
|
|
await database.SaveChangesAsync(cancellationToken);
|
|
logger.LogInformation("Deleted {Count} old Expired upload intents past retention window", oldExpiredIntents.Count);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|