Fixed duplicate notifications #3398

This commit is contained in:
Jamie Rees 2020-02-17 21:48:12 +00:00
parent 0e7cbe5c6b
commit 72403f21f6
4 changed files with 41 additions and 10 deletions

View file

@ -1,4 +1,6 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Quartz; using Quartz;
using Quartz.Impl; using Quartz.Impl;
@ -36,6 +38,12 @@ namespace Ombi.Helpers
return Scheduler; return Scheduler;
} }
public static async Task<bool> IsJobRunnung(string jobName)
{
var running = await Scheduler.GetCurrentlyExecutingJobs();
return running.Any(x => x.JobDetail.Key.Name.Equals(jobName, StringComparison.InvariantCultureIgnoreCase));
}
public async Task AddJob<T>(string name, string group, string cronExpression, Dictionary<string, string> jobData = null) public async Task AddJob<T>(string name, string group, string cronExpression, Dictionary<string, string> jobData = null)
where T : IJob where T : IJob
{ {

View file

@ -32,7 +32,7 @@ namespace Ombi.Notifications.Agents
protected override bool ValidateConfiguration(TwilioSettings settings) protected override bool ValidateConfiguration(TwilioSettings settings)
{ {
if (!settings.WhatsAppSettings?.Enabled ?? false) if (!settings?.WhatsAppSettings?.Enabled ?? false)
{ {
return false; return false;
} }

View file

@ -116,16 +116,31 @@ namespace Ombi.Schedule.Jobs.Plex
} }
if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch) if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch)
{
// 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"); Logger.LogInformation("Kicking off Plex Availability Checker");
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex");
} }
}
if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch) if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch)
{ {
// 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"); 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); 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);
await Notification.Clients.Clients(NotificationHub.AdminConnectionIds) await Notification.Clients.Clients(NotificationHub.AdminConnectionIds)

View file

@ -64,7 +64,15 @@ namespace Ombi.Schedule.Jobs.Plex
} }
await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System");
// 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 OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex");
}
await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
.SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Finished"); .SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Finished");
} }