New: Added health check warning to emphasis when a artist was deleted instead of only logging it in System Events

This commit is contained in:
Taloth Saldono 2019-10-19 17:15:28 +02:00 committed by bakerboy448
parent d45b8cf1c7
commit 8567a7d6cb
5 changed files with 67 additions and 5 deletions

View file

@ -0,0 +1,53 @@
using System.Linq;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Localization;
using NzbDrone.Core.Music;
using NzbDrone.Core.Music.Events;
namespace NzbDrone.Core.HealthCheck.Checks
{
[CheckOn(typeof(ArtistUpdatedEvent))]
[CheckOn(typeof(ArtistsDeletedEvent), CheckOnCondition.FailedOnly)]
public class RemovedArtistCheck : HealthCheckBase, ICheckOnCondition<ArtistUpdatedEvent>, ICheckOnCondition<ArtistsDeletedEvent>
{
private readonly IArtistService _artistService;
private readonly Logger _logger;
public RemovedArtistCheck(ILocalizationService localizationService, IArtistService artistService, Logger logger)
: base(localizationService)
{
_artistService = artistService;
_logger = logger;
}
public override HealthCheck Check()
{
var deletedArtists = _artistService.GetAllArtists().Where(v => v.Metadata.Value.Status == ArtistStatusType.Deleted).ToList();
if (deletedArtists.Empty())
{
return new HealthCheck(GetType());
}
var artistText = deletedArtists.Select(s => $"{s.Name} (mbid {s.ForeignArtistId})").Join(", ");
if (deletedArtists.Count == 1)
{
return new HealthCheck(GetType(), HealthCheckResult.Error, $"Artist {artistText} was removed from MusicBrainz");
}
return new HealthCheck(GetType(), HealthCheckResult.Error, $"Artists {artistText} were removed from MusicBrainz");
}
public bool ShouldCheckOnEvent(ArtistsDeletedEvent deletedEvent)
{
return deletedEvent.Artists.Any(artist => artist.Metadata.Value.Status == ArtistStatusType.Deleted);
}
public bool ShouldCheckOnEvent(ArtistUpdatedEvent updatedEvent)
{
return updatedEvent.Artist.Metadata.Value.Status == ArtistStatusType.Deleted;
}
}
}

View file

@ -136,7 +136,7 @@ private void ProcessHealthChecks()
public void Execute(CheckHealthCommand message)
{
var healthChecks = message.Trigger == CommandTrigger.Manual ? _healthChecks : _scheduledHealthChecks;
var healthChecks = message.Trigger == CommandTrigger.Manual ? _healthChecks : _scheduledHealthChecks;
lock (_pendingHealthChecks)
{

View file

@ -2,6 +2,7 @@ namespace NzbDrone.Core.Music
{
public enum ArtistStatusType
{
Deleted = -1,
Continuing = 0,
Ended = 1
}

View file

@ -87,7 +87,15 @@ protected override RemoteData GetRemoteData(Artist local, List<Artist> remote)
}
catch (ArtistNotFoundException)
{
_logger.Error($"Could not find artist with id {local.Metadata.Value.ForeignArtistId}");
if (local.Metadata.Value.Status != ArtistStatusType.Deleted)
{
local.Metadata.Value.Status = ArtistStatusType.Deleted;
_artistService.UpdateArtist(local);
_logger.Debug("Artist marked as deleted on MusicBrainz for {0}", local.Name);
_eventAggregator.PublishEvent(new ArtistUpdatedEvent(local));
}
_logger.Error($"Artist '{local.Name}' (mbid {local.Metadata.Value.ForeignArtistId}) was not found, it may have been removed from MusicBrainz.");
}
return result;

View file

@ -42,9 +42,9 @@ public bool ShouldRefresh(Artist artist)
return false;
}
if (artist.Metadata.Value.Status == ArtistStatusType.Continuing && artist.LastInfoSync < DateTime.UtcNow.AddDays(-2))
if (artist.Metadata.Value.Status != ArtistStatusType.Ended && artist.LastInfoSync < DateTime.UtcNow.AddDays(-2))
{
_logger.Trace("Artist {0} is continuing and has not been refreshed in 2 days, should refresh.", artist.Name);
_logger.Trace("Artist {0} is not ended and has not been refreshed in 2 days, should refresh.", artist.Name);
return true;
}
@ -52,7 +52,7 @@ public bool ShouldRefresh(Artist artist)
if (lastAlbum != null && lastAlbum.ReleaseDate > DateTime.UtcNow.AddDays(-30))
{
_logger.Trace("Last album in {0} aired less than 30 days ago, should refresh.", artist.Name);
_logger.Trace("Last album in {0} released less than 30 days ago, should refresh.", artist.Name);
return true;
}