Completes the scheduled jobs module with default jobs, a themed scheduler page and aligned recovery semantics

This commit is contained in:
BinaryAlley committed 2026-09-04 13:56:04 -07:00
1 parent 99a6159f7f
commit 4b7cfbbe11
67 files changed
+3324 -745

No files matched your search

@@ -43,6 +43,16 @@ public class ScheduledJobExecutionEntity : IStorageEntity, IAuditableEntity
/// </summary>
public DateTime? CompletedOnUtc { get; init; }
/// <summary>
/// Gets a value indicating whether the execution cycle of the scheduled job was active when the execution started.
/// </summary>
/// <remarks>
/// A job whose execution cycle is active stays in its active state while a manually fired one time execution runs, so an
/// interrupted execution of such a job must return it to its active state at the next startup; the flag keeps that fact
/// separate from <see cref="IsCycleRun"/>, which records how the execution was triggered for the audit trail.
/// </remarks>
public required bool WasCycleActive { get; init; }
/// <summary>
/// Gets or sets the time and date when the entity was added.
/// </summary>
@@ -43,4 +43,12 @@ public interface IScheduledJobExecutionRepository : IRepository<ScheduledJobExec
/// <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>
Task<Result<Success>> DeleteByScheduledJobIdAsync(Guid scheduledJobId, CancellationToken cancellationToken);
/// <summary>
/// Removes all the executions of the tasks of scheduled jobs that started before <paramref name="cutoffUtc"/>, from the storage medium.
/// </summary>
/// <param name="cutoffUtc">The exclusive lower bound of the retained interval, in UTC; executions that started before it are removed.</param>
/// <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>
Task<Result<Success>> DeleteOlderThanAsync(DateTime cutoffUtc, CancellationToken cancellationToken);
}
@@ -22,6 +22,14 @@ public interface IScheduledJobRepository : IRepository<ScheduledJobEntity>,
IUpdateRepositoryAction<ScheduledJobEntity>,
IDeleteByIdRepositoryAction<Guid>
{
/// <summary>
/// Gets a scheduled job identified by <paramref name="id"/> from the storage medium, without tracking it.
/// </summary>
/// <param name="id">The id of the scheduled job to get.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="ScheduledJobEntity"/> identified by <paramref name="id"/>, or an error.</returns>
Task<Result<ScheduledJobEntity?>> GetByIdWithoutTrackingAsync(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Gets the scheduled jobs that have an active or running execution cycle, from the storage medium.
/// </summary>
@@ -43,4 +43,12 @@ public interface IDataSeedService
/// <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>
Task<Result<Created>> SetAdminRoleToAdministratorAccount(Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Sets up the default scheduled jobs, owned by the administrator account.
/// </summary>
/// <param name="adminUserId">The unique identifier of the administrator account that owns the default scheduled jobs.</param>
/// <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>
Task<Result<Created>> SetDefaultScheduledJobsAsync(Guid adminUserId, CancellationToken cancellationToken);
}
@@ -94,6 +94,14 @@ public static class ScheduledJobEntityMapping
return Result.From<Schedule>(intervalScheduleResult.Value);
}
if (repositoryEntity.ScheduleType == ScheduleType.OnceAtStartup)
{
Result<OnceAtStartupSchedule> onceAtStartupScheduleResult = OnceAtStartupSchedule.Create();
if (onceAtStartupScheduleResult.IsFailure)
return onceAtStartupScheduleResult.Errors;
return Result.From<Schedule>(onceAtStartupScheduleResult.Value);
}
Result<DailySchedule> dailyScheduleResult = DailySchedule.Create(repositoryEntity.Hour ?? 0, repositoryEntity.Minute ?? 0);
if (dailyScheduleResult.IsFailure)
return dailyScheduleResult.Errors;