Trigger queue cleaner sequentially (#14)

* added option to run queue cleaner after content blocker

* updated readme to clearly state what the jobs do
This commit is contained in:
Marius Nechifor
2024-11-25 21:33:06 +02:00
committed by GitHub
parent 599242aa2a
commit a0c8ff72fb
8 changed files with 118 additions and 44 deletions

View File

@@ -37,32 +37,33 @@ public static class QuartzDI
TriggersConfig triggersConfig
)
{
q.AddJob<QueueCleaner, QueueCleanerConfig>(
configuration,
QueueCleanerConfig.SectionName,
triggersConfig.QueueCleaner
);
ContentBlockerConfig? contentBlockerConfig = configuration
.GetRequiredSection(ContentBlockerConfig.SectionName)
.Get<ContentBlockerConfig>();
q.AddJob<ContentBlocker, ContentBlockerConfig>(
configuration,
ContentBlockerConfig.SectionName,
triggersConfig.ContentBlocker
);
q.AddJob<ContentBlocker>(contentBlockerConfig, triggersConfig.ContentBlocker);
QueueCleanerConfig? queueCleanerConfig = configuration
.GetRequiredSection(QueueCleanerConfig.SectionName)
.Get<QueueCleanerConfig>();
if (contentBlockerConfig?.Enabled is true && queueCleanerConfig is { Enabled: true, RunSequentially: true })
{
q.AddJob<QueueCleaner>(queueCleanerConfig, string.Empty);
q.AddJobListener(new JobChainingListener(nameof(QueueCleaner)));
}
else
{
q.AddJob<QueueCleaner>(queueCleanerConfig, triggersConfig.QueueCleaner);
}
}
private static void AddJob<T, TConfig>(
private static void AddJob<T>(
this IServiceCollectionQuartzConfigurator q,
IConfiguration configuration,
string configSectionName,
IJobConfig? config,
string trigger
)
where T: GenericHandler
where TConfig : IJobConfig
) where T: GenericHandler
{
IJobConfig? config = configuration
.GetRequiredSection(configSectionName)
.Get<TConfig>();
string typeName = typeof(T).Name;
if (config is null)
@@ -75,11 +76,25 @@ public static class QuartzDI
return;
}
bool hasTrigger = trigger.Length > 0;
q.AddJob<GenericJob<T>>(opts =>
{
opts.WithIdentity(typeName);
if (!hasTrigger)
{
// jobs with no triggers need to be stored durably
opts.StoreDurably();
}
});
// skip empty triggers
if (!hasTrigger)
{
return;
}
q.AddTrigger(opts =>
{
opts.ForJob(typeName)

View File

@@ -12,7 +12,7 @@
"ContentBlocker": "0/10 * * * * ?"
},
"ContentBlocker": {
"Enabled": false,
"Enabled": true,
"Blacklist": {
"Enabled": false,
"Path": "https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist"
@@ -23,7 +23,8 @@
}
},
"QueueCleaner": {
"Enabled": true
"Enabled": true,
"RunSequentially": true
},
"qBittorrent": {
"Enabled": true,

View File

@@ -23,7 +23,8 @@
}
},
"QueueCleaner": {
"Enabled": true
"Enabled": true,
"RunSequentially": true
},
"qBittorrent": {
"Enabled": true,