2020-09-07 03:29:24 +00:00
|
|
|
using System;
|
|
|
|
using NzbDrone.Common.Messaging;
|
|
|
|
|
2017-12-31 20:24:41 +00:00
|
|
|
namespace NzbDrone.Core.HealthCheck
|
|
|
|
{
|
2020-09-07 03:29:24 +00:00
|
|
|
public interface IEventDrivenHealthCheck
|
|
|
|
{
|
|
|
|
IProvideHealthCheck HealthCheck { get; }
|
|
|
|
|
|
|
|
bool ShouldExecute(IEvent message, bool previouslyFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EventDrivenHealthCheck<TEvent> : IEventDrivenHealthCheck
|
2017-12-31 20:24:41 +00:00
|
|
|
{
|
|
|
|
public IProvideHealthCheck HealthCheck { get; set; }
|
|
|
|
public CheckOnCondition Condition { get; set; }
|
2020-09-07 03:29:24 +00:00
|
|
|
public ICheckOnCondition<TEvent> EventFilter { get; set; }
|
2017-12-31 20:24:41 +00:00
|
|
|
|
|
|
|
public EventDrivenHealthCheck(IProvideHealthCheck healthCheck, CheckOnCondition condition)
|
|
|
|
{
|
|
|
|
HealthCheck = healthCheck;
|
|
|
|
Condition = condition;
|
2020-09-07 03:29:24 +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;
|
2017-12-31 20:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|