Adds a technical data cleanup scheduled job that fails interrupted media library scans at startup

This commit is contained in:
BinaryAlley committed 2026-09-29 12:00:00 +03:00
1 parent d33986096e
commit 80af18170a
26 files changed
+395 -10

No files matched your search

@@ -114,4 +114,20 @@ internal sealed class LibraryScanRepository : ILibraryScanRepository
EditableValuesCopier.CopyEditableValues(_luminaDbContext, foundLibraryScan, data);
return Result.Updated;
}
/// <summary>
/// Marks the media library scans that were interrupted by an application restart, meaning the ones that are still
/// <see cref="LibraryScanJobStatus.Pending"/> or <see cref="LibraryScanJobStatus.Running"/>, as failed.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<Updated>> FailInterruptedScansAsync(CancellationToken cancellationToken)
{
// The scans that were pending or running when the application stopped cannot survive the restart, because their jobs,
// progress and cancellation tokens live only in memory, so they are marked as failed and can be triggered again.
await _luminaDbContext.LibraryScans
.Where(libraryScan => libraryScan.Status == LibraryScanJobStatus.Pending || libraryScan.Status == LibraryScanJobStatus.Running)
.ExecuteUpdateAsync(setters => setters.SetProperty(libraryScan => libraryScan.Status, LibraryScanJobStatus.Failed), cancellationToken).ConfigureAwait(false);
return Result.Updated;
}
}
@@ -198,7 +198,9 @@ public class DataSeedService : IDataSeedService
// Repair the installed themes whose files are missing, at every application startup.
CreateDefaultScheduledJob("Repair themes at startup", ScheduledTaskType.RepairThemes, ScheduleType.OnceAtStartup, intervalMinutes: null, hour: null, minute: null, adminUserId),
// Clean the execution history of the scheduled jobs, keeping only the executions of the past month, at every application startup.
CreateDefaultScheduledJob("Clean scheduled job execution history at startup", ScheduledTaskType.CleanScheduledJobExecutionHistory, ScheduleType.OnceAtStartup, intervalMinutes: null, hour: null, minute: null, adminUserId)
CreateDefaultScheduledJob("Clean scheduled job execution history at startup", ScheduledTaskType.CleanScheduledJobExecutionHistory, ScheduleType.OnceAtStartup, intervalMinutes: null, hour: null, minute: null, adminUserId),
// Clean the technical data that is no longer valid, at every application startup.
CreateDefaultScheduledJob("Technical data cleanup at startup", ScheduledTaskType.TechnicalDataCleanup, ScheduleType.OnceAtStartup, intervalMinutes: null, hour: null, minute: null, adminUserId)
];
foreach (ScheduledJobEntity defaultScheduledJob in defaultScheduledJobs)
{