parent
ea9494019e
commit
0c44ee5f88
@ -0,0 +1,124 @@
|
|||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import React from 'react';
|
||||||
|
import { icons, kinds, sizes } from 'Helpers/Props';
|
||||||
|
import Icon from 'Components/Icon';
|
||||||
|
import ProgressBar from 'Components/ProgressBar';
|
||||||
|
import QueueDetails from 'Activity/Queue/QueueDetails';
|
||||||
|
import MovieQuality from 'Movie/MovieQuality';
|
||||||
|
import Label from 'Components/Label';
|
||||||
|
import styles from './MovieFileStatus.css';
|
||||||
|
|
||||||
|
function MovieFileStatus(props) {
|
||||||
|
const {
|
||||||
|
inCinemas,
|
||||||
|
isAvailable,
|
||||||
|
monitored,
|
||||||
|
grabbed,
|
||||||
|
queueItem,
|
||||||
|
movieFile
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const hasMovieFile = !!movieFile;
|
||||||
|
const isQueued = !!queueItem;
|
||||||
|
const hasReleased = isAvailable && inCinemas;
|
||||||
|
|
||||||
|
if (isQueued) {
|
||||||
|
const {
|
||||||
|
sizeleft,
|
||||||
|
size
|
||||||
|
} = queueItem;
|
||||||
|
|
||||||
|
const progress = (100 - sizeleft / size * 100);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.center}>
|
||||||
|
<QueueDetails
|
||||||
|
{...queueItem}
|
||||||
|
progressBar={
|
||||||
|
<ProgressBar
|
||||||
|
title={`Movie is downloading - ${progress.toFixed(1)}% ${queueItem.title}`}
|
||||||
|
progress={progress}
|
||||||
|
kind={kinds.PURPLE}
|
||||||
|
size={sizes.MEDIUM}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grabbed) {
|
||||||
|
return (
|
||||||
|
<div className={styles.center}>
|
||||||
|
<Icon
|
||||||
|
name={icons.DOWNLOADING}
|
||||||
|
title="Movie is downloading"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasMovieFile) {
|
||||||
|
const quality = movieFile.quality;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.center}>
|
||||||
|
<MovieQuality
|
||||||
|
title={quality.quality.name}
|
||||||
|
size={movieFile.size}
|
||||||
|
quality={quality}
|
||||||
|
isMonitored={monitored}
|
||||||
|
isCutoffNotMet={movieFile.qualityCutoffNotMet}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!monitored) {
|
||||||
|
return (
|
||||||
|
<div className={styles.center}>
|
||||||
|
<Label
|
||||||
|
title="Announced"
|
||||||
|
kind={kinds.WARNING}
|
||||||
|
>
|
||||||
|
Not Monitored
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasReleased) {
|
||||||
|
return (
|
||||||
|
<div className={styles.center}>
|
||||||
|
<Label
|
||||||
|
title="Movie Available, but Missing"
|
||||||
|
kind={kinds.DANGER}
|
||||||
|
>
|
||||||
|
Missing
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.center}>
|
||||||
|
<Label
|
||||||
|
title="Announced"
|
||||||
|
kind={kinds.INFO}
|
||||||
|
>
|
||||||
|
Not Available
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
MovieFileStatus.propTypes = {
|
||||||
|
inCinemas: PropTypes.string,
|
||||||
|
isAvailable: PropTypes.bool,
|
||||||
|
monitored: PropTypes.bool.isRequired,
|
||||||
|
grabbed: PropTypes.bool,
|
||||||
|
queueItem: PropTypes.object,
|
||||||
|
movieFile: PropTypes.object
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MovieFileStatus;
|
@ -0,0 +1,75 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.HealthCheck.Checks;
|
||||||
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.HealthCheck.Checks
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class RemovedSeriesCheckFixture : CoreTest<RemovedSeriesCheck>
|
||||||
|
{
|
||||||
|
private void GivenMovie(int amount, int deleted)
|
||||||
|
{
|
||||||
|
List<Movie> movie;
|
||||||
|
|
||||||
|
if (amount == 0)
|
||||||
|
{
|
||||||
|
movie = new List<Movie>();
|
||||||
|
}
|
||||||
|
else if (deleted == 0)
|
||||||
|
{
|
||||||
|
movie = Builder<Movie>.CreateListOfSize(amount)
|
||||||
|
.All()
|
||||||
|
.With(v => v.Status = MovieStatusType.Released)
|
||||||
|
.BuildList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
movie = Builder<Movie>.CreateListOfSize(amount)
|
||||||
|
.All()
|
||||||
|
.With(v => v.Status = MovieStatusType.Released)
|
||||||
|
.Random(deleted)
|
||||||
|
.With(v => v.Status = MovieStatusType.Deleted)
|
||||||
|
.BuildList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Mocker.GetMock<IMovieService>()
|
||||||
|
.Setup(v => v.GetAllMovies())
|
||||||
|
.Returns(movie);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_error_if_movie_no_longer_on_tmdb()
|
||||||
|
{
|
||||||
|
GivenMovie(4, 1);
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeError();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_error_if_multiple_movie_no_longer_on_tmdb()
|
||||||
|
{
|
||||||
|
GivenMovie(4, 2);
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeError();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_ok_if_all_movie_still_on_tmdb()
|
||||||
|
{
|
||||||
|
GivenMovie(4, 0);
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_ok_if_no_movie_exist()
|
||||||
|
{
|
||||||
|
GivenMovie(0, 0);
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeOk();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Cache;
|
||||||
|
using NzbDrone.Common.Messaging;
|
||||||
|
using NzbDrone.Core.HealthCheck;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.HealthCheck
|
||||||
|
{
|
||||||
|
public class HealthCheckServiceFixture : CoreTest<HealthCheckService>
|
||||||
|
{
|
||||||
|
private FakeHealthCheck _healthCheck;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
_healthCheck = new FakeHealthCheck();
|
||||||
|
|
||||||
|
Mocker.SetConstant<IEnumerable<IProvideHealthCheck>>(new[] { _healthCheck });
|
||||||
|
Mocker.SetConstant<ICacheManager>(Mocker.Resolve<CacheManager>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_execute_conditional()
|
||||||
|
{
|
||||||
|
Subject.HandleAsync(new FakeEvent());
|
||||||
|
|
||||||
|
_healthCheck.Executed.Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_execute_conditional()
|
||||||
|
{
|
||||||
|
Subject.HandleAsync(new FakeEvent() { ShouldExecute = true });
|
||||||
|
|
||||||
|
_healthCheck.Executed.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_execute_unconditional()
|
||||||
|
{
|
||||||
|
Subject.HandleAsync(new FakeEvent2());
|
||||||
|
|
||||||
|
_healthCheck.Executed.Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FakeEvent : IEvent
|
||||||
|
{
|
||||||
|
public bool ShouldExecute { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FakeEvent2 : IEvent
|
||||||
|
{
|
||||||
|
public bool ShouldExecute { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[CheckOn(typeof(FakeEvent))]
|
||||||
|
[CheckOn(typeof(FakeEvent2))]
|
||||||
|
public class FakeHealthCheck : IProvideHealthCheck, ICheckOnCondition<FakeEvent>
|
||||||
|
{
|
||||||
|
public bool CheckOnStartup => false;
|
||||||
|
public bool CheckOnSchedule => false;
|
||||||
|
|
||||||
|
public bool Executed { get; set; }
|
||||||
|
public bool Checked { get; set; }
|
||||||
|
|
||||||
|
public Core.HealthCheck.HealthCheck Check()
|
||||||
|
{
|
||||||
|
Executed = true;
|
||||||
|
|
||||||
|
return new Core.HealthCheck.HealthCheck(GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShouldCheckOnEvent(FakeEvent message)
|
||||||
|
{
|
||||||
|
return message.ShouldExecute;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Movies.Events;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.HealthCheck.Checks
|
||||||
|
{
|
||||||
|
[CheckOn(typeof(MovieUpdatedEvent))]
|
||||||
|
[CheckOn(typeof(MovieDeletedEvent), CheckOnCondition.FailedOnly)]
|
||||||
|
public class RemovedSeriesCheck : HealthCheckBase, ICheckOnCondition<MovieUpdatedEvent>, ICheckOnCondition<MovieDeletedEvent>
|
||||||
|
{
|
||||||
|
private readonly IMovieService _movieService;
|
||||||
|
|
||||||
|
public RemovedSeriesCheck(IMovieService movieService)
|
||||||
|
{
|
||||||
|
_movieService = movieService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override HealthCheck Check()
|
||||||
|
{
|
||||||
|
var deletedMovie = _movieService.GetAllMovies().Where(v => v.Status == MovieStatusType.Deleted).ToList();
|
||||||
|
|
||||||
|
if (deletedMovie.Empty())
|
||||||
|
{
|
||||||
|
return new HealthCheck(GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
var movieText = deletedMovie.Select(s => $"{s.Title} (tmdbid {s.TmdbId})").Join(", ");
|
||||||
|
|
||||||
|
if (deletedMovie.Count == 1)
|
||||||
|
{
|
||||||
|
return new HealthCheck(GetType(), HealthCheckResult.Error, $"Movie {movieText} was removed from TMDb");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HealthCheck(GetType(), HealthCheckResult.Error, $"Movie {movieText} were removed from TMDb");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShouldCheckOnEvent(MovieDeletedEvent message)
|
||||||
|
{
|
||||||
|
return message.Movie.Status == MovieStatusType.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShouldCheckOnEvent(MovieUpdatedEvent message)
|
||||||
|
{
|
||||||
|
return message.Movie.Status == MovieStatusType.Deleted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,45 @@
|
|||||||
|
using NzbDrone.Common.Messaging;
|
||||||
|
|
||||||
namespace NzbDrone.Core.HealthCheck
|
namespace NzbDrone.Core.HealthCheck
|
||||||
{
|
{
|
||||||
public class EventDrivenHealthCheck
|
public interface IEventDrivenHealthCheck
|
||||||
|
{
|
||||||
|
IProvideHealthCheck HealthCheck { get; }
|
||||||
|
|
||||||
|
bool ShouldExecute(IEvent message, bool previouslyFailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EventDrivenHealthCheck<TEvent> : IEventDrivenHealthCheck
|
||||||
{
|
{
|
||||||
public IProvideHealthCheck HealthCheck { get; set; }
|
public IProvideHealthCheck HealthCheck { get; set; }
|
||||||
public CheckOnCondition Condition { get; set; }
|
public CheckOnCondition Condition { get; set; }
|
||||||
|
public ICheckOnCondition<TEvent> EventFilter { get; set; }
|
||||||
|
|
||||||
public EventDrivenHealthCheck(IProvideHealthCheck healthCheck, CheckOnCondition condition)
|
public EventDrivenHealthCheck(IProvideHealthCheck healthCheck, CheckOnCondition condition)
|
||||||
{
|
{
|
||||||
HealthCheck = healthCheck;
|
HealthCheck = healthCheck;
|
||||||
Condition = condition;
|
Condition = condition;
|
||||||
|
EventFilter = healthCheck as ICheckOnCondition<TEvent>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShouldExecute(IEvent message, bool previouslyFailed)
|
||||||
|
{
|
||||||
|
if (Condition == CheckOnCondition.SuccessfulOnly && previouslyFailed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Condition == CheckOnCondition.FailedOnly && !previouslyFailed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EventFilter != null && !EventFilter.ShouldCheckOnEvent((TEvent)message))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace NzbDrone.Core.HealthCheck
|
||||||
|
{
|
||||||
|
public interface ICheckOnCondition<TEvent>
|
||||||
|
{
|
||||||
|
bool ShouldCheckOnEvent(TEvent message);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue