mirror of
https://github.com/Lidarr/Lidarr
synced 2025-12-06 16:33:52 +01:00
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:
parent
d45b8cf1c7
commit
8567a7d6cb
5 changed files with 67 additions and 5 deletions
53
src/NzbDrone.Core/HealthCheck/Checks/RemovedArtistCheck.cs
Normal file
53
src/NzbDrone.Core/HealthCheck/Checks/RemovedArtistCheck.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -136,7 +136,7 @@ private void ProcessHealthChecks()
|
||||||
|
|
||||||
public void Execute(CheckHealthCommand message)
|
public void Execute(CheckHealthCommand message)
|
||||||
{
|
{
|
||||||
var healthChecks = message.Trigger == CommandTrigger.Manual ? _healthChecks : _scheduledHealthChecks;
|
var healthChecks = message.Trigger == CommandTrigger.Manual ? _healthChecks : _scheduledHealthChecks;
|
||||||
|
|
||||||
lock (_pendingHealthChecks)
|
lock (_pendingHealthChecks)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
public enum ArtistStatusType
|
public enum ArtistStatusType
|
||||||
{
|
{
|
||||||
|
Deleted = -1,
|
||||||
Continuing = 0,
|
Continuing = 0,
|
||||||
Ended = 1
|
Ended = 1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,15 @@ protected override RemoteData GetRemoteData(Artist local, List<Artist> remote)
|
||||||
}
|
}
|
||||||
catch (ArtistNotFoundException)
|
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;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,9 @@ public bool ShouldRefresh(Artist artist)
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ public bool ShouldRefresh(Artist artist)
|
||||||
|
|
||||||
if (lastAlbum != null && lastAlbum.ReleaseDate > DateTime.UtcNow.AddDays(-30))
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue