From 4003bd3fd1926558f2c955f2fc353b0f0fe57c81 Mon Sep 17 00:00:00 2001 From: da3dsoul Date: Wed, 10 Jan 2024 10:52:35 -0500 Subject: [PATCH] Create Attributes for Determining Acquisition Requirements and Annotate the Existing Jobs --- .../Acquisition/AniDBHTTPRateLimitedAttribute.cs | 5 +++++ .../Acquisition/AniDBUDPRateLimitedAttribute.cs | 5 +++++ .../Acquisition/DatabaseRequiredAttribute.cs | 6 ++++++ .../Scheduling/Acquisition/NetworkRequiredAttribute.cs | 6 ++++++ .../Jobs/Actions/CheckNetworkAvailabilityJob.cs | 2 +- Shoko.Server/Scheduling/Jobs/Actions/ImportJob.cs | 4 +++- Shoko.Server/Scheduling/Jobs/Actions/MediaInfoJob.cs | 4 +++- .../Scheduling/Jobs/Actions/RemoveMissingFilesJob.cs | 4 +++- .../Scheduling/Jobs/Actions/ScanDropFoldersJob.cs | 4 +++- Shoko.Server/Scheduling/Jobs/AniDB/AniDBGetFileJob.cs | 5 ++++- Shoko.Server/Scheduling/Jobs/JobKeyGroup.cs | 10 ++++++++++ .../Scheduling/Jobs/Shoko/DeleteImportFolderJob.cs | 4 +++- Shoko.Server/Scheduling/Jobs/Shoko/DiscoverFileJob.cs | 4 ++++ Shoko.Server/Scheduling/Jobs/Shoko/HashFileJob.cs | 4 ++++ Shoko.Server/Scheduling/Jobs/Shoko/ScanFolderJob.cs | 4 +++- 15 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 Shoko.Server/Scheduling/Acquisition/AniDBHTTPRateLimitedAttribute.cs create mode 100644 Shoko.Server/Scheduling/Acquisition/AniDBUDPRateLimitedAttribute.cs create mode 100644 Shoko.Server/Scheduling/Acquisition/DatabaseRequiredAttribute.cs create mode 100644 Shoko.Server/Scheduling/Acquisition/NetworkRequiredAttribute.cs create mode 100644 Shoko.Server/Scheduling/Jobs/JobKeyGroup.cs diff --git a/Shoko.Server/Scheduling/Acquisition/AniDBHTTPRateLimitedAttribute.cs b/Shoko.Server/Scheduling/Acquisition/AniDBHTTPRateLimitedAttribute.cs new file mode 100644 index 000000000..627a5bd1e --- /dev/null +++ b/Shoko.Server/Scheduling/Acquisition/AniDBHTTPRateLimitedAttribute.cs @@ -0,0 +1,5 @@ +using System; + +namespace Shoko.Server.Scheduling.Acquisition; + +public class AniDBHTTPRateLimitedAttribute : Attribute { } diff --git a/Shoko.Server/Scheduling/Acquisition/AniDBUDPRateLimitedAttribute.cs b/Shoko.Server/Scheduling/Acquisition/AniDBUDPRateLimitedAttribute.cs new file mode 100644 index 000000000..3f1ec8214 --- /dev/null +++ b/Shoko.Server/Scheduling/Acquisition/AniDBUDPRateLimitedAttribute.cs @@ -0,0 +1,5 @@ +using System; + +namespace Shoko.Server.Scheduling.Acquisition; + +public class AniDBUDPRateLimitedAttribute : Attribute { } diff --git a/Shoko.Server/Scheduling/Acquisition/DatabaseRequiredAttribute.cs b/Shoko.Server/Scheduling/Acquisition/DatabaseRequiredAttribute.cs new file mode 100644 index 000000000..1a91f5eea --- /dev/null +++ b/Shoko.Server/Scheduling/Acquisition/DatabaseRequiredAttribute.cs @@ -0,0 +1,6 @@ +using System; + +namespace Shoko.Server.Scheduling.Acquisition; + +[AttributeUsage(AttributeTargets.Class)] +public class DatabaseRequiredAttribute : Attribute { } diff --git a/Shoko.Server/Scheduling/Acquisition/NetworkRequiredAttribute.cs b/Shoko.Server/Scheduling/Acquisition/NetworkRequiredAttribute.cs new file mode 100644 index 000000000..e1c7c1f18 --- /dev/null +++ b/Shoko.Server/Scheduling/Acquisition/NetworkRequiredAttribute.cs @@ -0,0 +1,6 @@ +using System; + +namespace Shoko.Server.Scheduling.Acquisition; + +[AttributeUsage(AttributeTargets.Class)] +public class NetworkRequiredAttribute : Attribute { } diff --git a/Shoko.Server/Scheduling/Jobs/Actions/CheckNetworkAvailabilityJob.cs b/Shoko.Server/Scheduling/Jobs/Actions/CheckNetworkAvailabilityJob.cs index c8a18fe60..7df46e355 100644 --- a/Shoko.Server/Scheduling/Jobs/Actions/CheckNetworkAvailabilityJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Actions/CheckNetworkAvailabilityJob.cs @@ -11,7 +11,7 @@ namespace Shoko.Server.Scheduling.Jobs.Actions; [JobKeyMember("UptimeMonitor")] -[JobKeyGroup("System")] +[JobKeyGroup(JobKeyGroup.System)] [DisallowConcurrentExecution] public class CheckNetworkAvailabilityJob : IJob { diff --git a/Shoko.Server/Scheduling/Jobs/Actions/ImportJob.cs b/Shoko.Server/Scheduling/Jobs/Actions/ImportJob.cs index a72cd7c2a..3ad6975ee 100644 --- a/Shoko.Server/Scheduling/Jobs/Actions/ImportJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Actions/ImportJob.cs @@ -6,11 +6,13 @@ using System.Threading.Tasks; using Quartz; using QuartzJobFactory.Attributes; +using Shoko.Server.Scheduling.Acquisition; namespace Shoko.Server.Scheduling.Jobs.Actions; +[DatabaseRequired] [JobKeyMember("Import")] -[JobKeyGroup("Legacy")] +[JobKeyGroup(JobKeyGroup.Legacy)] [DisallowConcurrentExecution] internal class ImportJob : IJob { diff --git a/Shoko.Server/Scheduling/Jobs/Actions/MediaInfoJob.cs b/Shoko.Server/Scheduling/Jobs/Actions/MediaInfoJob.cs index 7a82b25f3..43b142617 100644 --- a/Shoko.Server/Scheduling/Jobs/Actions/MediaInfoJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Actions/MediaInfoJob.cs @@ -8,11 +8,13 @@ using QuartzJobFactory.Attributes; using Shoko.Server.Commands; using Shoko.Server.Repositories; +using Shoko.Server.Scheduling.Acquisition; namespace Shoko.Server.Scheduling.Jobs.Actions; +[DatabaseRequired] [JobKeyMember("MediaInfo")] -[JobKeyGroup("Legacy")] +[JobKeyGroup(JobKeyGroup.Legacy)] internal class MediaInfoJob : IJob { private readonly ICommandRequestFactory _commandRequestFactory; diff --git a/Shoko.Server/Scheduling/Jobs/Actions/RemoveMissingFilesJob.cs b/Shoko.Server/Scheduling/Jobs/Actions/RemoveMissingFilesJob.cs index 64bcbcd09..17489dd9c 100644 --- a/Shoko.Server/Scheduling/Jobs/Actions/RemoveMissingFilesJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Actions/RemoveMissingFilesJob.cs @@ -6,11 +6,13 @@ using System.Threading.Tasks; using Quartz; using QuartzJobFactory.Attributes; +using Shoko.Server.Scheduling.Acquisition; namespace Shoko.Server.Scheduling.Jobs.Actions; +[DatabaseRequired] [JobKeyMember("RemoveMissingFiles")] -[JobKeyGroup("Legacy")] +[JobKeyGroup(JobKeyGroup.Legacy)] [DisallowConcurrentExecution] internal class RemoveMissingFilesJob : IJob { diff --git a/Shoko.Server/Scheduling/Jobs/Actions/ScanDropFoldersJob.cs b/Shoko.Server/Scheduling/Jobs/Actions/ScanDropFoldersJob.cs index d49243c29..7d15c20a1 100644 --- a/Shoko.Server/Scheduling/Jobs/Actions/ScanDropFoldersJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Actions/ScanDropFoldersJob.cs @@ -6,11 +6,13 @@ using System.Threading.Tasks; using Quartz; using QuartzJobFactory.Attributes; +using Shoko.Server.Scheduling.Acquisition; namespace Shoko.Server.Scheduling.Jobs.Actions; +[DatabaseRequired] [JobKeyMember("ScanDropFolders")] -[JobKeyGroup("Legacy")] +[JobKeyGroup(JobKeyGroup.Legacy)] internal class ScanDropFoldersJob : IJob { public Task Execute(IJobExecutionContext context) diff --git a/Shoko.Server/Scheduling/Jobs/AniDB/AniDBGetFileJob.cs b/Shoko.Server/Scheduling/Jobs/AniDB/AniDBGetFileJob.cs index 5be1ef415..1d6ef180d 100644 --- a/Shoko.Server/Scheduling/Jobs/AniDB/AniDBGetFileJob.cs +++ b/Shoko.Server/Scheduling/Jobs/AniDB/AniDBGetFileJob.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using Quartz; +using QuartzJobFactory.Attributes; using Shoko.Commons.Queue; using Shoko.Models.Enums; using Shoko.Models.Queue; @@ -16,12 +16,15 @@ using Shoko.Server.Providers.AniDB.UDP.Generic; using Shoko.Server.Providers.AniDB.UDP.Info; using Shoko.Server.Repositories; +using Shoko.Server.Scheduling.Acquisition; using Shoko.Server.Scheduling.Concurrency; using Shoko.Server.Server; namespace Shoko.Server.Scheduling.Jobs.AniDB; +[DatabaseRequired, NetworkRequired, AniDBUDPRateLimited] [DisallowConcurrencyGroup(ConcurrencyGroups.AniDB_UDP)] +[JobKeyGroup(JobKeyGroup.AniDB)] [Command(CommandRequestType.AniDB_GetFileUDP)] public class AniDBGetFileJob : BaseJob { diff --git a/Shoko.Server/Scheduling/Jobs/JobKeyGroup.cs b/Shoko.Server/Scheduling/Jobs/JobKeyGroup.cs new file mode 100644 index 000000000..506e854e0 --- /dev/null +++ b/Shoko.Server/Scheduling/Jobs/JobKeyGroup.cs @@ -0,0 +1,10 @@ +namespace Shoko.Server.Scheduling.Jobs; + +public static class JobKeyGroup +{ + public const string Import = "Import"; + public const string AniDB = "AniDB"; + public const string Legacy = "Legacy"; + public const string System = "System"; + public const string Actions = "Actions"; +} diff --git a/Shoko.Server/Scheduling/Jobs/Shoko/DeleteImportFolderJob.cs b/Shoko.Server/Scheduling/Jobs/Shoko/DeleteImportFolderJob.cs index a3d88d2ae..48ecdda6a 100644 --- a/Shoko.Server/Scheduling/Jobs/Shoko/DeleteImportFolderJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Shoko/DeleteImportFolderJob.cs @@ -6,11 +6,13 @@ using System.Threading.Tasks; using Quartz; using QuartzJobFactory.Attributes; +using Shoko.Server.Scheduling.Acquisition; namespace Shoko.Server.Scheduling.Jobs.Shoko; +[DatabaseRequired] [JobKeyMember("DeleteImportFolder")] -[JobKeyGroup("Actions")] +[JobKeyGroup(JobKeyGroup.Actions)] internal class DeleteImportFolderJob : IJob { public int ImportFolderID { get; set; } diff --git a/Shoko.Server/Scheduling/Jobs/Shoko/DiscoverFileJob.cs b/Shoko.Server/Scheduling/Jobs/Shoko/DiscoverFileJob.cs index 21fd9f3ce..0bb1255d0 100644 --- a/Shoko.Server/Scheduling/Jobs/Shoko/DiscoverFileJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Shoko/DiscoverFileJob.cs @@ -5,17 +5,21 @@ using Microsoft.Extensions.Logging; using Quartz; using QuartzJobFactory; +using QuartzJobFactory.Attributes; using Shoko.Commons.Queue; using Shoko.Models.Queue; using Shoko.Server.Databases; using Shoko.Server.Models; using Shoko.Server.Repositories; using Shoko.Server.Repositories.Cached; +using Shoko.Server.Scheduling.Acquisition; using Shoko.Server.Server; using Shoko.Server.Settings; namespace Shoko.Server.Scheduling.Jobs.Shoko; +[DatabaseRequired] +[JobKeyGroup(JobKeyGroup.Import)] public class DiscoverFileJob : BaseJob { public virtual string FileName { get; set; } diff --git a/Shoko.Server/Scheduling/Jobs/Shoko/HashFileJob.cs b/Shoko.Server/Scheduling/Jobs/Shoko/HashFileJob.cs index dbce36d70..d05da4902 100644 --- a/Shoko.Server/Scheduling/Jobs/Shoko/HashFileJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Shoko/HashFileJob.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Quartz; +using QuartzJobFactory.Attributes; using Shoko.Commons.Queue; using Shoko.Models.Queue; using Shoko.Models.Server; @@ -15,6 +16,7 @@ using Shoko.Server.Models; using Shoko.Server.Repositories; using Shoko.Server.Repositories.Cached; +using Shoko.Server.Scheduling.Acquisition; using Shoko.Server.Scheduling.Concurrency; using Shoko.Server.Server; using Shoko.Server.Settings; @@ -22,7 +24,9 @@ namespace Shoko.Server.Scheduling.Jobs.Shoko; +[DatabaseRequired] [LimitConcurrency] +[JobKeyGroup(JobKeyGroup.Import)] public class HashFileJob : BaseJob { public virtual string FileName { get; set; } diff --git a/Shoko.Server/Scheduling/Jobs/Shoko/ScanFolderJob.cs b/Shoko.Server/Scheduling/Jobs/Shoko/ScanFolderJob.cs index 816883554..12f691801 100644 --- a/Shoko.Server/Scheduling/Jobs/Shoko/ScanFolderJob.cs +++ b/Shoko.Server/Scheduling/Jobs/Shoko/ScanFolderJob.cs @@ -6,11 +6,13 @@ using System.Threading.Tasks; using Quartz; using QuartzJobFactory.Attributes; +using Shoko.Server.Scheduling.Acquisition; namespace Shoko.Server.Scheduling.Jobs.Shoko; +[DatabaseRequired] [JobKeyMember("ScanFolder")] -[JobKeyGroup("Actions")] +[JobKeyGroup(JobKeyGroup.Actions)] internal class ScanFolderJob : IJob { [JobKeyMember]