From 21e59072d030c1096f999a944fa2663d6406d035 Mon Sep 17 00:00:00 2001 From: Marius Nechifor Date: Thu, 9 Jan 2025 23:03:53 +0200 Subject: [PATCH] Increase trigger interval limit (#34) --- README.md | 4 ++-- code/Common/Helpers/Constants.cs | 7 +++++++ code/Common/Helpers/StaticConfiguration.cs | 6 ++++++ code/Executable/DependencyInjection/QuartzDI.cs | 13 ++++++++++--- .../Infrastructure/Verticals/ItemStriker/Striker.cs | 5 +++-- 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 code/Common/Helpers/Constants.cs create mode 100644 code/Common/Helpers/StaticConfiguration.cs diff --git a/README.md b/README.md index cdf1442..df19acd 100644 --- a/README.md +++ b/README.md @@ -139,8 +139,8 @@ services: | LOGGING__FILE__PATH | No | Directory where to save the log files | empty | | LOGGING__ENHANCED | No | Enhance logs whenever possible
A more detailed description is provided [here](variables.md#LOGGING__ENHANCED) | true | ||||| -| TRIGGERS__QUEUECLEANER | Yes if queue cleaner is enabled | [Quartz cron trigger](https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html)
Can be a max of 1h interval | 0 0/5 * * * ? | -| TRIGGERS__CONTENTBLOCKER | Yes if content blocker is enabled | [Quartz cron trigger](https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html)
Can be a max of 1h interval | 0 0/5 * * * ? | +| TRIGGERS__QUEUECLEANER | Yes if queue cleaner is enabled | [Quartz cron trigger](https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html)
Can be a max of 6h interval
**Is ignored if `QUEUECLEANER__RUNSEQUENTIALLY=true` and `CONTENTBLOCKER__ENABLED=true`** | 0 0/5 * * * ? | +| TRIGGERS__CONTENTBLOCKER | Yes if content blocker is enabled | [Quartz cron trigger](https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html)
Can be a max of 6h interval | 0 0/5 * * * ? | ||||| | QUEUECLEANER__ENABLED | No | Enable or disable the queue cleaner | true | | QUEUECLEANER__RUNSEQUENTIALLY | No | If set to true, the queue cleaner will run after the content blocker instead of running in parallel, streamlining the cleaning process | true | diff --git a/code/Common/Helpers/Constants.cs b/code/Common/Helpers/Constants.cs new file mode 100644 index 0000000..ac35f59 --- /dev/null +++ b/code/Common/Helpers/Constants.cs @@ -0,0 +1,7 @@ +namespace Common.Helpers; + +public static class Constants +{ + public static readonly TimeSpan TriggerMaxLimit = TimeSpan.FromHours(6); + public static readonly TimeSpan CacheLimitBuffer = TimeSpan.FromHours(2); +} \ No newline at end of file diff --git a/code/Common/Helpers/StaticConfiguration.cs b/code/Common/Helpers/StaticConfiguration.cs new file mode 100644 index 0000000..225df86 --- /dev/null +++ b/code/Common/Helpers/StaticConfiguration.cs @@ -0,0 +1,6 @@ +namespace Common.Helpers; + +public static class StaticConfiguration +{ + public static TimeSpan TriggerValue { get; set; } = TimeSpan.Zero; +} \ No newline at end of file diff --git a/code/Executable/DependencyInjection/QuartzDI.cs b/code/Executable/DependencyInjection/QuartzDI.cs index 534d9a8..6d3d732 100644 --- a/code/Executable/DependencyInjection/QuartzDI.cs +++ b/code/Executable/DependencyInjection/QuartzDI.cs @@ -1,6 +1,7 @@ using Common.Configuration; using Common.Configuration.ContentBlocker; using Common.Configuration.QueueCleaner; +using Common.Helpers; using Executable.Jobs; using Infrastructure.Verticals.ContentBlocker; using Infrastructure.Verticals.Jobs; @@ -96,18 +97,24 @@ public static class QuartzDI return; } - var triggerObj = (IOperableTrigger)TriggerBuilder.Create() + IOperableTrigger triggerObj = (IOperableTrigger)TriggerBuilder.Create() .WithIdentity("ExampleTrigger") .StartNow() .WithCronSchedule(trigger) .Build(); - var nextFireTimes = TriggerUtils.ComputeFireTimes(triggerObj, null, 2); + IReadOnlyList nextFireTimes = TriggerUtils.ComputeFireTimes(triggerObj, null, 2); + TimeSpan triggerValue = nextFireTimes[1] - nextFireTimes[0]; - if (nextFireTimes[1] - nextFireTimes[0] > TimeSpan.FromHours(1)) + if (triggerValue > Constants.TriggerMaxLimit) { throw new Exception($"{trigger} should have a fire time of maximum 1 hour"); } + + if (triggerValue > StaticConfiguration.TriggerValue) + { + StaticConfiguration.TriggerValue = triggerValue; + } q.AddTrigger(opts => { diff --git a/code/Infrastructure/Verticals/ItemStriker/Striker.cs b/code/Infrastructure/Verticals/ItemStriker/Striker.cs index d07a3ae..a30b262 100644 --- a/code/Infrastructure/Verticals/ItemStriker/Striker.cs +++ b/code/Infrastructure/Verticals/ItemStriker/Striker.cs @@ -1,4 +1,5 @@ -using Domain.Enums; +using Common.Helpers; +using Domain.Enums; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; @@ -15,7 +16,7 @@ public class Striker _logger = logger; _cache = cache; _cacheOptions = new MemoryCacheEntryOptions() - .SetSlidingExpiration(TimeSpan.FromHours(2)); + .SetSlidingExpiration(StaticConfiguration.TriggerValue + Constants.CacheLimitBuffer); } public bool StrikeAndCheckLimit(string hash, string itemName, ushort maxStrikes, StrikeType strikeType)