diff --git a/src/Ombi.Helpers/OmbiQuartz.cs b/src/Ombi.Helpers/OmbiQuartz.cs index 7979bc2a7..e5be66a6c 100644 --- a/src/Ombi.Helpers/OmbiQuartz.cs +++ b/src/Ombi.Helpers/OmbiQuartz.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Quartz; using Quartz.Impl; @@ -36,6 +38,12 @@ namespace Ombi.Helpers return Scheduler; } + public static async Task IsJobRunnung(string jobName) + { + var running = await Scheduler.GetCurrentlyExecutingJobs(); + return running.Any(x => x.JobDetail.Key.Name.Equals(jobName, StringComparison.InvariantCultureIgnoreCase)); + } + public async Task AddJob(string name, string group, string cronExpression, Dictionary jobData = null) where T : IJob { diff --git a/src/Ombi.Notifications/Agents/WhatsAppNotification.cs b/src/Ombi.Notifications/Agents/WhatsAppNotification.cs index 860acc8d0..ae41dc09e 100644 --- a/src/Ombi.Notifications/Agents/WhatsAppNotification.cs +++ b/src/Ombi.Notifications/Agents/WhatsAppNotification.cs @@ -32,7 +32,7 @@ namespace Ombi.Notifications.Agents protected override bool ValidateConfiguration(TwilioSettings settings) { - if (!settings.WhatsAppSettings?.Enabled ?? false) + if (!settings?.WhatsAppSettings?.Enabled ?? false) { return false; } diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index 8af14a125..b001878ff 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -117,14 +117,29 @@ namespace Ombi.Schedule.Jobs.Plex if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch) { - Logger.LogInformation("Kicking off Plex Availability Checker"); - await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); + // Ensure it's not already running + if (await OmbiQuartz.IsJobRunnung(nameof(IPlexAvailabilityChecker))) + { + Logger.LogInformation("Availability checker already running"); + } + else + { + Logger.LogInformation("Kicking off Plex Availability Checker"); + await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); + } } if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch) { - - await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); + // Ensure it's not already running + if (await OmbiQuartz.IsJobRunnung(nameof(IPlexAvailabilityChecker))) + { + Logger.LogInformation("Availability checker already running"); + } + else + { + await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); + } } Logger.LogInformation("Finished Plex Content Cacher, with processed content: {0}, episodes: {1}. Recently Added Scan: {2}", processedContent?.Content?.Count() ?? 0, processedContent?.Episodes?.Count() ?? 0, recentlyAddedSearch); @@ -183,7 +198,7 @@ namespace Ombi.Schedule.Jobs.Plex { Logger.LogDebug("Found some episodes, this must be a recently added sync"); var count = 0; - foreach (var epInfo in content.Metadata ?? new Metadata[]{}) + foreach (var epInfo in content.Metadata ?? new Metadata[] { }) { count++; var grandParentKey = epInfo.grandparentRatingKey; @@ -391,7 +406,7 @@ namespace Ombi.Schedule.Jobs.Plex await Repo.Delete(existingKey); existingKey = null; } - else if(existingContent == null) + else if (existingContent == null) { existingContent = await Repo.GetFirstContentByCustom(x => x.Key == show.ratingKey); } @@ -509,7 +524,7 @@ namespace Ombi.Schedule.Jobs.Plex // But it does not contain the `guid` property that we need to pull out thetvdb id... var showMetadata = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri, show.ratingKey); - + var item = new PlexServerContent { AddedAt = DateTime.Now, diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index da022390f..e75ca1b4b 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -64,7 +64,15 @@ namespace Ombi.Schedule.Jobs.Plex } await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); - await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); + // Ensure it's not already running + if (await OmbiQuartz.IsJobRunnung(nameof(IPlexAvailabilityChecker))) + { + _log.LogInformation("Availability checker already running"); + } + else + { + await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); + } await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) .SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Finished"); }