mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
feat(archival): ✨ schedule daily archival
This commit is contained in:
parent
71f4b8a840
commit
29db802eba
4 changed files with 41 additions and 19 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.Enqueue(new ArchiveList.Command(list.Id));
|
||||
_mediator.EnqueueBackgroundJob(new ArchiveList.Command(list.Id));
|
||||
}
|
||||
|
||||
return Unit.Value;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
using FilterLists.Archival.Infrastructure;
|
||||
using System;
|
||||
using FilterLists.Archival.Application.Commands;
|
||||
using FilterLists.Archival.Infrastructure;
|
||||
using FilterLists.Archival.Infrastructure.Scheduling;
|
||||
using Hangfire;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
@ -23,6 +27,15 @@ public static void AddApplicationServices(this IServiceCollection services, ICon
|
|||
public static void UseApplication(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseInfrastructure();
|
||||
app.ScheduleArchival();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,22 +6,38 @@
|
|||
namespace FilterLists.Archival.Infrastructure.Scheduling
|
||||
{
|
||||
/// <remarks>https://codeopinion.com/background-commands-mediatr-hangfire/</remarks>
|
||||
public static class MediatorExtensions
|
||||
{
|
||||
public static void EnqueueBackgroundJob(this IMediator _, IRequest request)
|
||||
{
|
||||
BackgroundJob.Enqueue<HangfireMediator>(m => m.Send(request));
|
||||
}
|
||||
|
||||
public static void AddOrUpdateRecurringJob(
|
||||
this IMediator _,
|
||||
IRequest request,
|
||||
Func<string> cronExpression)
|
||||
{
|
||||
RecurringJob.AddOrUpdate<HangfireMediator>(m => m.Send(request), cronExpression);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class HangfireExtension
|
||||
{
|
||||
public static IGlobalConfiguration UseMediatR(this IGlobalConfiguration config, IMediator mediator)
|
||||
{
|
||||
config.UseActivator(new MediatRJobActivator(mediator));
|
||||
config.UseActivator(new MediatorJobActivator(mediator));
|
||||
GlobalConfiguration.Configuration.UseSerializerSettings(
|
||||
new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Objects});
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
internal class MediatRJobActivator : JobActivator
|
||||
internal class MediatorJobActivator : JobActivator
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public MediatRJobActivator(IMediator mediator)
|
||||
public MediatorJobActivator(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
|
@ -41,17 +57,9 @@ public HangfireMediator(IMediator mediator)
|
|||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public void SendCommand(IRequest request)
|
||||
public void Send(IRequest request)
|
||||
{
|
||||
_mediator.Send(request);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MediatRExtension
|
||||
{
|
||||
public static void Enqueue(this IMediator mediator, IRequest request)
|
||||
{
|
||||
BackgroundJob.Enqueue<HangfireMediator>(m => m.SendCommand(request));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
|
||||
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=FilterLists_0020Cleanup/@EntryIndexedValue"><?xml version="1.0" encoding="utf-16"?><Profile name="FilterLists Cleanup"><CSReorderTypeMembers>True</CSReorderTypeMembers><XMLReformatCode>True</XMLReformatCode><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" ArrangeTrailingCommas="True" /><RemoveCodeRedundanciesVB>True</RemoveCodeRedundanciesVB><Xaml.RedundantFreezeAttribute>True</Xaml.RedundantFreezeAttribute><Xaml.RemoveRedundantModifiersAttribute>True</Xaml.RemoveRedundantModifiersAttribute><Xaml.RemoveRedundantNameAttribute>True</Xaml.RemoveRedundantNameAttribute><Xaml.RemoveRedundantResource>True</Xaml.RemoveRedundantResource><Xaml.RemoveRedundantCollectionProperty>True</Xaml.RemoveRedundantCollectionProperty><Xaml.RemoveRedundantAttachedPropertySetter>True</Xaml.RemoveRedundantAttachedPropertySetter><Xaml.RemoveRedundantStyledValue>True</Xaml.RemoveRedundantStyledValue><Xaml.RemoveRedundantNamespaceAlias>True</Xaml.RemoveRedundantNamespaceAlias><Xaml.RemoveForbiddenResourceName>True</Xaml.RemoveForbiddenResourceName><Xaml.RemoveRedundantGridDefinitionsAttribute>True</Xaml.RemoveRedundantGridDefinitionsAttribute><Xaml.RemoveRedundantGridSpanAttribut>True</Xaml.RemoveRedundantGridSpanAttribut><Xaml.RemoveRedundantUpdateSourceTriggerAttribute>True</Xaml.RemoveRedundantUpdateSourceTriggerAttribute><Xaml.RemoveRedundantBindingModeAttribute>True</Xaml.RemoveRedundantBindingModeAttribute><FormatAttributeQuoteDescriptor>True</FormatAttributeQuoteDescriptor><CorrectVariableKindsDescriptor>True</CorrectVariableKindsDescriptor><VariablesToInnerScopesDescriptor>True</VariablesToInnerScopesDescriptor><StringToTemplatesDescriptor>True</StringToTemplatesDescriptor><RemoveRedundantQualifiersTs>True</RemoveRedundantQualifiersTs><OptimizeImportsTs>True</OptimizeImportsTs><OptimizeReferenceCommentsTs>True</OptimizeReferenceCommentsTs><PublicModifierStyleTs>True</PublicModifierStyleTs><ExplicitAnyTs>True</ExplicitAnyTs><TypeAnnotationStyleTs>True</TypeAnnotationStyleTs><RelativePathStyleTs>True</RelativePathStyleTs><AsInsteadOfCastTs>True</AsInsteadOfCastTs><CssAlphabetizeProperties>True</CssAlphabetizeProperties><JsInsertSemicolon>True</JsInsertSemicolon><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><HtmlReformatCode>True</HtmlReformatCode><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSArrangeQualifiers>True</CSArrangeQualifiers><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences><CssReformatCode>True</CssReformatCode><VBReformatCode>True</VBReformatCode><VBFormatDocComments>True</VBFormatDocComments><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments></Profile></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">FilterLists Cleanup</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_EMBEDDED_STATEMENT_ON_SAME_LINE/@EntryValue">NEVER</s:String>
|
||||
|
|
@ -7,9 +10,7 @@
|
|||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_BINARY_EXPRESSIONS/@EntryValue">CHOP_IF_LONG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_METHOD_CALLS/@EntryValue">CHOP_IF_LONG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_PARAMETERS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Hangfire/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mediat/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Primariness/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Syntaxes/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
Loading…
Reference in a new issue