mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(archival): ♻ extend IRequest rather than unused IMediator
This commit is contained in:
parent
29db802eba
commit
739268a624
3 changed files with 5 additions and 10 deletions
|
|
@ -28,7 +28,7 @@ public async Task<Unit> Handle(Command request, CancellationToken cancellationTo
|
|||
var lists = await _directory.GetListsAsync(cancellationToken);
|
||||
foreach (var list in lists)
|
||||
{
|
||||
_mediator.EnqueueBackgroundJob(new ArchiveList.Command(list.Id));
|
||||
new ArchiveList.Command(list.Id).EnqueueBackgroundJob();
|
||||
}
|
||||
|
||||
return Unit.Value;
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ public static void UseApplication(this IApplicationBuilder app)
|
|||
private static void ScheduleArchival(this IApplicationBuilder app)
|
||||
{
|
||||
_ = app ?? throw new ArgumentNullException(nameof(app));
|
||||
|
||||
var mediator = (IMediator)app.ApplicationServices.GetService(typeof(IMediator));
|
||||
mediator.AddOrUpdateRecurringJob(new EnqueueArchiveAllLists.Command(), Cron.Daily);
|
||||
new EnqueueArchiveAllLists.Command().AddOrUpdateRecurringJob(Cron.Daily);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,14 @@
|
|||
namespace FilterLists.Archival.Infrastructure.Scheduling
|
||||
{
|
||||
/// <remarks>https://codeopinion.com/background-commands-mediatr-hangfire/</remarks>
|
||||
public static class MediatorExtensions
|
||||
public static class RequestExtensions
|
||||
{
|
||||
public static void EnqueueBackgroundJob(this IMediator _, IRequest request)
|
||||
public static void EnqueueBackgroundJob(this IRequest request)
|
||||
{
|
||||
BackgroundJob.Enqueue<HangfireMediator>(m => m.Send(request));
|
||||
}
|
||||
|
||||
public static void AddOrUpdateRecurringJob(
|
||||
this IMediator _,
|
||||
IRequest request,
|
||||
Func<string> cronExpression)
|
||||
public static void AddOrUpdateRecurringJob(this IRequest request, Func<string> cronExpression)
|
||||
{
|
||||
RecurringJob.AddOrUpdate<HangfireMediator>(m => m.Send(request), cronExpression);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue