Adds scheduled job contracts and application handlers

This commit is contained in:
BinaryAlley committed 2026-09-03 12:48:53 -07:00
1 parent 7fbb4dc0d3
commit ea7e003bff
51 files changed
+2442

No files matched your search

@@ -0,0 +1,90 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.Scheduling;
/// <summary>
/// Repository entity for a scheduled job.
/// </summary>
[DebuggerDisplay("Id: {Id}, Status: {Status}")]
public class ScheduledJobEntity : IStorageEntity, IAuditableEntity
{
/// <summary>
/// Gets the Id of the scheduled job.
/// </summary>
public required Guid Id { get; init; }
/// <summary>
/// Gets the name of the scheduled job.
/// </summary>
public required string Name { get; init; }
/// <summary>
/// Gets the type of the task executed by the scheduled job.
/// </summary>
public required ScheduledTaskType TaskType { get; init; }
/// <summary>
/// Gets the type of the schedule of the scheduled job.
/// </summary>
public required ScheduleType ScheduleType { get; init; }
/// <summary>
/// Gets the interval in minutes of the schedule of the scheduled job, when its <see cref="ScheduleType"/> is <see cref="ScheduleType.WithIntervalInMinutes"/>.
/// </summary>
public int? IntervalMinutes { get; init; }
/// <summary>
/// Gets the hour of the schedule of the scheduled job, when its <see cref="ScheduleType"/> is <see cref="ScheduleType.DailyAtHourAndMinute"/>.
/// </summary>
public int? Hour { get; init; }
/// <summary>
/// Gets the minute of the schedule of the scheduled job, when its <see cref="ScheduleType"/> is <see cref="ScheduleType.DailyAtHourAndMinute"/>.
/// </summary>
public int? Minute { get; init; }
/// <summary>
/// Gets the status of the scheduled job.
/// </summary>
public required ScheduledJobStatus Status { get; init; }
/// <summary>
/// Gets the Id of the user that owns the scheduled job.
/// </summary>
public required Guid OwnerUserId { get; init; }
/// <summary>
/// Gets the optional date and time when the task of the scheduled job last started its execution.
/// </summary>
public DateTime? LastStartedOnUtc { get; init; }
/// <summary>
/// Gets the optional date and time when the task of the scheduled job last completed its execution.
/// </summary>
public DateTime? LastCompletedOnUtc { get; init; }
/// <summary>
/// Gets or sets the time and date when the entity was added.
/// </summary>
public required DateTime CreatedOnUtc { get; set; }
/// <summary>
/// Gets or sets the Id of the user that created the entity.
/// </summary>
public required Guid CreatedBy { get; set; }
/// <summary>
/// Gets or sets the optional time and date when the entity was updated.
/// </summary>
public DateTime? UpdatedOnUtc { get; set; }
/// <summary>
/// Gets or sets the optional Id of the user that updated the entity.
/// </summary>
public required Guid? UpdatedBy { get; set; }
}
@@ -0,0 +1,65 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.Scheduling;
/// <summary>
/// Repository entity for an execution of the task of a scheduled job.
/// </summary>
[DebuggerDisplay("Id: {Id}, ScheduledJobId: {ScheduledJobId}")]
public class ScheduledJobExecutionEntity : IStorageEntity, IAuditableEntity
{
/// <summary>
/// Gets the Id of the execution of the task of a scheduled job.
/// </summary>
public required Guid Id { get; init; }
/// <summary>
/// Gets the Id of the scheduled job whose task was executed.
/// </summary>
public required Guid ScheduledJobId { get; init; }
/// <summary>
/// Gets the type of the task that was executed.
/// </summary>
public required ScheduledTaskType TaskType { get; init; }
/// <summary>
/// Gets a value indicating whether the execution was triggered by the execution cycle of the scheduled job, or it was a one time execution.
/// </summary>
public required bool IsCycleRun { get; init; }
/// <summary>
/// Gets the date and time when the execution started.
/// </summary>
public required DateTime StartedOnUtc { get; init; }
/// <summary>
/// Gets the optional date and time when the execution completed.
/// </summary>
public DateTime? CompletedOnUtc { get; init; }
/// <summary>
/// Gets or sets the time and date when the entity was added.
/// </summary>
public required DateTime CreatedOnUtc { get; set; }
/// <summary>
/// Gets or sets the Id of the user that created the entity.
/// </summary>
public required Guid CreatedBy { get; set; }
/// <summary>
/// Gets or sets the optional time and date when the entity was updated.
/// </summary>
public DateTime? UpdatedOnUtc { get; set; }
/// <summary>
/// Gets or sets the optional Id of the user that updated the entity.
/// </summary>
public required Guid? UpdatedBy { get; set; }
}
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Scheduling;
/// <summary>
/// Interface for the repository for the executions of the tasks of scheduled jobs.
/// </summary>
public interface IScheduledJobExecutionRepository : IRepository<ScheduledJobExecutionEntity>,
IGetByIdRepositoryAction<ScheduledJobExecutionEntity, Guid>,
IInsertRepositoryAction<ScheduledJobExecutionEntity>,
IUpdateRepositoryAction<ScheduledJobExecutionEntity>
{
/// <summary>
/// Gets the most recent execution of the task of a scheduled job identified by <paramref name="scheduledJobId"/> that is still running, from the storage medium.
/// </summary>
/// <param name="scheduledJobId">The Id of the scheduled job whose running execution is retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the running execution of the scheduled job, or <see langword="null"/>.</returns>
Task<Result<ScheduledJobExecutionEntity?>> GetOpenByScheduledJobIdAsync(Guid scheduledJobId, CancellationToken cancellationToken);
/// <summary>
/// Gets the executions of the tasks of scheduled jobs that started in the interval between <paramref name="fromUtc"/> and <paramref name="toUtc"/>, from the storage medium.
/// </summary>
/// <param name="fromUtc">The inclusive lower bound of the interval, in UTC.</param>
/// <param name="toUtc">The inclusive upper bound of the interval, in UTC.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="ScheduledJobExecutionEntity"/>, or an error.</returns>
Task<Result<IEnumerable<ScheduledJobExecutionEntity>>> GetByTimeRangeAsync(DateTime fromUtc, DateTime toUtc, CancellationToken cancellationToken);
/// <summary>
/// Removes all the executions of the task of a scheduled job identified by <paramref name="scheduledJobId"/>, from the storage medium.
/// </summary>
/// <param name="scheduledJobId">The Id of the scheduled job whose executions 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>> DeleteByScheduledJobIdAsync(Guid scheduledJobId, CancellationToken cancellationToken);
}
@@ -0,0 +1,31 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Scheduling;
/// <summary>
/// Interface for the repository for scheduled jobs.
/// </summary>
public interface IScheduledJobRepository : IRepository<ScheduledJobEntity>,
IGetByIdRepositoryAction<ScheduledJobEntity, Guid>,
IGetAllRepositoryAction<ScheduledJobEntity>,
IInsertRepositoryAction<ScheduledJobEntity>,
IUpdateRepositoryAction<ScheduledJobEntity>,
IDeleteByIdRepositoryAction<Guid>
{
/// <summary>
/// Gets the scheduled jobs that have an active or running execution cycle, from the storage medium.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="ScheduledJobEntity"/>, or an error.</returns>
Task<Result<IEnumerable<ScheduledJobEntity>>> GetActiveOrRunningAsync(CancellationToken cancellationToken);
}
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.Repositories.MediaContributors;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
using Lumina.Application.Common.DataAccess.Repositories.Themes;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using System.Threading;
@@ -87,6 +88,16 @@ public interface IUnitOfWork
/// </summary>
ILibraryBookReaderConfigurationRepository LibraryBookReaderConfigurationRepository { get; }
/// <summary>
/// Gets the scheduled job repository.
/// </summary>
IScheduledJobRepository ScheduledJobRepository { get; }
/// <summary>
/// Gets the scheduled job execution repository.
/// </summary>
IScheduledJobExecutionRepository ScheduledJobExecutionRepository { get; }
/// <summary>
/// Gets the plugin repository.
/// </summary>