Prevent should refresh artists and albums from failing

(cherry picked from commit 3eed84c67938fed308e562e69cf7bcd727063803)
This commit is contained in:
Mark McDowall 2025-05-21 17:17:19 -07:00 committed by Bogdan
parent ae9b4cec75
commit 1bcb82eed0
2 changed files with 55 additions and 39 deletions

View file

@ -19,26 +19,34 @@ namespace NzbDrone.Core.Music
public bool ShouldRefresh(Album album)
{
if (album.LastInfoSync < DateTime.UtcNow.AddDays(-60))
try
{
_logger.Trace("Album {0} last updated more than 60 days ago, should refresh.", album.Title);
return true;
}
if (album.LastInfoSync < DateTime.UtcNow.AddDays(-60))
{
_logger.Trace("Album {0} last updated more than 60 days ago, should refresh.", album.Title);
return true;
}
if (album.LastInfoSync >= DateTime.UtcNow.AddHours(-12))
{
_logger.Trace("Album {0} last updated less than 12 hours ago, should not be refreshed.", album.Title);
if (album.LastInfoSync >= DateTime.UtcNow.AddHours(-12))
{
_logger.Trace("Album {0} last updated less than 12 hours ago, should not be refreshed.", album.Title);
return false;
}
if (album.ReleaseDate > DateTime.UtcNow.AddDays(-30))
{
_logger.Trace("album {0} released less than 30 days ago, should refresh.", album.Title);
return true;
}
_logger.Trace("Album {0} released long ago and recently refreshed, should not be refreshed.", album.Title);
return false;
}
if (album.ReleaseDate > DateTime.UtcNow.AddDays(-30))
catch (Exception e)
{
_logger.Trace("album {0} released less than 30 days ago, should refresh.", album.Title);
_logger.Error(e, "Unable to determine if album should refresh, will try to refresh.");
return true;
}
_logger.Trace("Album {0} released long ago and recently refreshed, should not be refreshed.", album.Title);
return false;
}
}
}

View file

@ -22,40 +22,48 @@ namespace NzbDrone.Core.Music
public bool ShouldRefresh(Artist artist)
{
if (artist.LastInfoSync == null)
try
{
_logger.Trace("Artist {0} was just added, should refresh.", artist.Name);
return true;
}
if (artist.LastInfoSync == null)
{
_logger.Trace("Artist {0} was just added, should refresh.", artist.Name);
return true;
}
if (artist.LastInfoSync < DateTime.UtcNow.AddDays(-30))
{
_logger.Trace("Artist {0} last updated more than 30 days ago, should refresh.", artist.Name);
return true;
}
if (artist.LastInfoSync < DateTime.UtcNow.AddDays(-30))
{
_logger.Trace("Artist {0} last updated more than 30 days ago, should refresh.", artist.Name);
return true;
}
if (artist.LastInfoSync >= DateTime.UtcNow.AddHours(-12))
{
_logger.Trace("Artist {0} last updated less than 12 hours ago, should not be refreshed.", artist.Name);
if (artist.LastInfoSync >= DateTime.UtcNow.AddHours(-12))
{
_logger.Trace("Artist {0} last updated less than 12 hours ago, should not be refreshed.", artist.Name);
return false;
}
if (artist.Metadata.Value.Status == ArtistStatusType.Continuing && artist.LastInfoSync < DateTime.UtcNow.AddDays(-2))
{
_logger.Trace("Artist {0} is continuing and has not been refreshed in 2 days, should refresh.", artist.Name);
return true;
}
var lastAlbum = _albumService.GetAlbumsByArtist(artist.Id).MaxBy(e => e.ReleaseDate);
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);
return true;
}
_logger.Trace("Artist {0} ended long ago, should not be refreshed.", artist.Name);
return false;
}
if (artist.Metadata.Value.Status == ArtistStatusType.Continuing && artist.LastInfoSync < DateTime.UtcNow.AddDays(-2))
catch (Exception e)
{
_logger.Trace("Artist {0} is continuing and has not been refreshed in 2 days, should refresh.", artist.Name);
_logger.Error(e, "Unable to determine if artist should refresh, will try to refresh.");
return true;
}
var lastAlbum = _albumService.GetAlbumsByArtist(artist.Id).MaxBy(e => e.ReleaseDate);
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);
return true;
}
_logger.Trace("Artist {0} ended long ago, should not be refreshed.", artist.Name);
return false;
}
}
}