2020-02-26 04:18:49 +00:00
|
|
|
using NzbDrone.Common.Messaging;
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
namespace NzbDrone.Core.HealthCheck
|
|
|
|
{
|
2020-02-26 04:18:49 +00:00
|
|
|
public interface IEventDrivenHealthCheck
|
|
|
|
{
|
|
|
|
IProvideHealthCheck HealthCheck { get; }
|
|
|
|
|
|
|
|
bool ShouldExecute(IEvent message, bool previouslyFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EventDrivenHealthCheck<TEvent> : IEventDrivenHealthCheck
|
2019-06-14 03:54:25 +00:00
|
|
|
{
|
|
|
|
public IProvideHealthCheck HealthCheck { get; set; }
|
|
|
|
public CheckOnCondition Condition { get; set; }
|
2020-02-26 04:18:49 +00:00
|
|
|
public ICheckOnCondition<TEvent> EventFilter { get; set; }
|
2019-06-14 03:54:25 +00:00
|
|
|
|
|
|
|
public EventDrivenHealthCheck(IProvideHealthCheck healthCheck, CheckOnCondition condition)
|
|
|
|
{
|
|
|
|
HealthCheck = healthCheck;
|
|
|
|
Condition = condition;
|
2020-02-26 04:18:49 +00:00
|
|
|
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;
|
2019-06-14 03:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|