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>
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.Infrastructure.Scheduling;
/// <summary>
/// Interface for the service that schedules and executes the tasks of scheduled jobs.
/// </summary>
public interface IScheduledJobScheduler
{
/// <summary>
/// Starts the execution cycle of the scheduled job identified by <paramref name="scheduledJobId"/>.
/// </summary>
/// <param name="scheduledJobId">The object representing the unique identifier of the scheduled job whose execution cycle is started.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
Task StartCycleAsync(ScheduledJobId scheduledJobId, CancellationToken cancellationToken);
/// <summary>
/// Stops the execution cycle of the scheduled job identified by <paramref name="scheduledJobId"/>.
/// </summary>
/// <param name="scheduledJobId">The object representing the unique identifier of the scheduled job whose execution cycle is stopped.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
Task StopCycleAsync(ScheduledJobId scheduledJobId, CancellationToken cancellationToken);
/// <summary>
/// Fires the task of the scheduled job identified by <paramref name="scheduledJobId"/> once, without affecting its execution cycle.
/// </summary>
/// <param name="scheduledJobId">The object representing the unique identifier of the scheduled job whose task is fired.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
Task RunOnceAsync(ScheduledJobId scheduledJobId, CancellationToken cancellationToken);
}
@@ -0,0 +1,29 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Scheduling.Commands.AddScheduledJob;
using Lumina.Contracts.Requests.Scheduling;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="AddScheduledJobRequest"/>.
/// </summary>
public static class AddScheduledJobRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="AddScheduledJobCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static AddScheduledJobCommand ToCommand(this AddScheduledJobRequest request)
{
return new AddScheduledJobCommand(
request.Name,
request.TaskType,
request.ScheduleType,
request.IntervalMinutes,
request.Hour,
request.Minute
);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Scheduling.Commands.FireScheduledJob;
using Lumina.Contracts.Requests.Scheduling;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="FireScheduledJobRequest"/>.
/// </summary>
public static class FireScheduledJobRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="FireScheduledJobCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static FireScheduledJobCommand ToCommand(this FireScheduledJobRequest request)
{
return new FireScheduledJobCommand(
request.ScheduledJobId
);
}
}
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Scheduling.Queries.GetScheduledJobHistory;
using Lumina.Contracts.Requests.Scheduling;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="GetScheduledJobHistoryRequest"/>.
/// </summary>
public static class GetScheduledJobHistoryRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetScheduledJobHistoryQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetScheduledJobHistoryQuery ToQuery(this GetScheduledJobHistoryRequest request)
{
return new GetScheduledJobHistoryQuery(
request.From,
request.To
);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Scheduling.Commands.RemoveScheduledJob;
using Lumina.Contracts.Requests.Scheduling;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="RemoveScheduledJobRequest"/>.
/// </summary>
public static class RemoveScheduledJobRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="RemoveScheduledJobCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static RemoveScheduledJobCommand ToCommand(this RemoveScheduledJobRequest request)
{
return new RemoveScheduledJobCommand(
request.ScheduledJobId
);
}
}
@@ -0,0 +1,102 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
using Lumina.Contracts.Responses.Scheduling;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate;
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="ScheduledJobEntity"/>.
/// </summary>
public static class ScheduledJobEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="ScheduledJob"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a converted <see cref="ScheduledJob"/>, or an error message.
/// </returns>
public static Result<ScheduledJob> ToDomainEntity(this ScheduledJobEntity repositoryEntity)
{
Result<Schedule> scheduleResult = CreateSchedule(repositoryEntity);
if (scheduleResult.IsFailure)
return scheduleResult.Errors;
return ScheduledJob.Create(
ScheduledJobId.Create(repositoryEntity.Id),
repositoryEntity.Name,
repositoryEntity.TaskType,
scheduleResult.Value,
UserId.Create(repositoryEntity.OwnerUserId),
repositoryEntity.Status,
Optional<DateTime>.FromNullable(repositoryEntity.LastStartedOnUtc),
Optional<DateTime>.FromNullable(repositoryEntity.LastCompletedOnUtc)
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="ScheduledJob"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="ScheduledJob"/>, or an error message.
/// </returns>
public static IEnumerable<Result<ScheduledJob>> ToDomainEntities(this IEnumerable<ScheduledJobEntity> repositoryEntities)
{
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
}
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="ScheduledJobResponse"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted scheduled job response.</returns>
public static ScheduledJobResponse ToResponse(this ScheduledJobEntity repositoryEntity)
{
return new ScheduledJobResponse(
repositoryEntity.Id,
repositoryEntity.Name,
repositoryEntity.TaskType,
repositoryEntity.ScheduleType,
repositoryEntity.IntervalMinutes,
repositoryEntity.Hour,
repositoryEntity.Minute,
repositoryEntity.Status,
repositoryEntity.LastStartedOnUtc,
repositoryEntity.LastCompletedOnUtc
);
}
/// <summary>
/// Creates the schedule of <paramref name="repositoryEntity"/> from its flattened schedule properties.
/// </summary>
/// <param name="repositoryEntity">The repository entity whose schedule is created.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a created <see cref="Schedule"/>, or an error message.
/// </returns>
private static Result<Schedule> CreateSchedule(ScheduledJobEntity repositoryEntity)
{
if (repositoryEntity.ScheduleType == ScheduleType.WithIntervalInMinutes)
{
Result<IntervalSchedule> intervalScheduleResult = IntervalSchedule.Create(repositoryEntity.IntervalMinutes ?? 0);
if (intervalScheduleResult.IsFailure)
return intervalScheduleResult.Errors;
return Result.From<Schedule>(intervalScheduleResult.Value);
}
Result<DailySchedule> dailyScheduleResult = DailySchedule.Create(repositoryEntity.Hour ?? 0, repositoryEntity.Minute ?? 0);
if (dailyScheduleResult.IsFailure)
return dailyScheduleResult.Errors;
return Result.From<Schedule>(dailyScheduleResult.Value);
}
}
@@ -0,0 +1,29 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
using Lumina.Contracts.Responses.Scheduling;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="ScheduledJobExecutionEntity"/>.
/// </summary>
public static class ScheduledJobExecutionEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="ScheduledJobExecutionResponse"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted execution response.</returns>
public static ScheduledJobExecutionResponse ToResponse(this ScheduledJobExecutionEntity repositoryEntity)
{
return new ScheduledJobExecutionResponse(
repositoryEntity.Id,
repositoryEntity.ScheduledJobId,
repositoryEntity.TaskType,
repositoryEntity.IsCycleRun,
repositoryEntity.StartedOnUtc,
repositoryEntity.CompletedOnUtc
);
}
}
@@ -0,0 +1,93 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
using Lumina.Contracts.Responses.Scheduling;
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate;
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
using System;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="ScheduledJob"/>.
/// </summary>
public static class ScheduledJobMapping
{
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="ScheduledJobEntity"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static ScheduledJobEntity ToRepositoryEntity(this ScheduledJob domainEntity)
{
return new ScheduledJobEntity
{
Id = domainEntity.Id.Value,
Name = domainEntity.Name,
TaskType = domainEntity.TaskType,
ScheduleType = domainEntity.Schedule.ScheduleType,
IntervalMinutes = GetIntervalMinutes(domainEntity),
Hour = GetHour(domainEntity),
Minute = GetMinute(domainEntity),
Status = domainEntity.Status,
OwnerUserId = domainEntity.OwnerUserId.Value,
LastStartedOnUtc = domainEntity.LastStartedOnUtc.HasValue ? domainEntity.LastStartedOnUtc.Value : null,
LastCompletedOnUtc = domainEntity.LastCompletedOnUtc.HasValue ? domainEntity.LastCompletedOnUtc.Value : null,
CreatedOnUtc = domainEntity.CreatedOnUtc,
CreatedBy = Guid.Empty,
UpdatedOnUtc = domainEntity.UpdatedOnUtc,
UpdatedBy = Guid.Empty
};
}
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="ScheduledJobResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted scheduled job response.</returns>
public static ScheduledJobResponse ToResponse(this ScheduledJob domainEntity)
{
return new ScheduledJobResponse(
domainEntity.Id.Value,
domainEntity.Name,
domainEntity.TaskType,
domainEntity.Schedule.ScheduleType,
GetIntervalMinutes(domainEntity),
GetHour(domainEntity),
GetMinute(domainEntity),
domainEntity.Status,
domainEntity.LastStartedOnUtc.HasValue ? domainEntity.LastStartedOnUtc.Value : null,
domainEntity.LastCompletedOnUtc.HasValue ? domainEntity.LastCompletedOnUtc.Value : null
);
}
/// <summary>
/// Gets the interval in minutes of the schedule of <paramref name="domainEntity"/>, when it is an interval schedule.
/// </summary>
/// <param name="domainEntity">The scheduled job whose schedule interval is retrieved.</param>
/// <returns>The interval in minutes of the schedule, or <see langword="null"/> when the schedule is not an interval schedule.</returns>
private static int? GetIntervalMinutes(ScheduledJob domainEntity)
{
return domainEntity.Schedule is IntervalSchedule intervalSchedule ? intervalSchedule.IntervalMinutes : null;
}
/// <summary>
/// Gets the hour of the schedule of <paramref name="domainEntity"/>, when it is a daily schedule.
/// </summary>
/// <param name="domainEntity">The scheduled job whose schedule hour is retrieved.</param>
/// <returns>The hour of the schedule, or <see langword="null"/> when the schedule is not a daily schedule.</returns>
private static int? GetHour(ScheduledJob domainEntity)
{
return domainEntity.Schedule is DailySchedule dailySchedule ? dailySchedule.Hour : null;
}
/// <summary>
/// Gets the minute of the schedule of <paramref name="domainEntity"/>, when it is a daily schedule.
/// </summary>
/// <param name="domainEntity">The scheduled job whose schedule minute is retrieved.</param>
/// <returns>The minute of the schedule, or <see langword="null"/> when the schedule is not a daily schedule.</returns>
private static int? GetMinute(ScheduledJob domainEntity)
{
return domainEntity.Schedule is DailySchedule dailySchedule ? dailySchedule.Minute : null;
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Scheduling.Commands.StartScheduledJob;
using Lumina.Contracts.Requests.Scheduling;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="StartScheduledJobRequest"/>.
/// </summary>
public static class StartScheduledJobRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="StartScheduledJobCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static StartScheduledJobCommand ToCommand(this StartScheduledJobRequest request)
{
return new StartScheduledJobCommand(
request.ScheduledJobId
);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Scheduling.Commands.StopScheduledJob;
using Lumina.Contracts.Requests.Scheduling;
#endregion
namespace Lumina.Application.Common.Mapping.Scheduling;
/// <summary>
/// Extension methods for converting <see cref="StopScheduledJobRequest"/>.
/// </summary>
public static class StopScheduledJobRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="StopScheduledJobCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static StopScheduledJobCommand ToCommand(this StopScheduledJobRequest request)
{
return new StopScheduledJobCommand(
request.ScheduledJobId
);
}
}