Skip to content

Commit

Permalink
#50
Browse files Browse the repository at this point in the history
* added var to modify mail on success behaviour
  • Loading branch information
mrksoftware committed Mar 31, 2020
1 parent eae8cb9 commit d4d58c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ public interface IAmConfigurationModelWithResolution : IAmBaseConfigurationModel

[JsonProperty(PropertyName = "sendReminderEmailAfterRetryCount")]
public int SendReminderEmailAfterRetryCount { get; set; }

[JsonProperty(PropertyName = "sendSuccessMailOnlyIfMaxRetryCountExceeded")]
public bool SendSuccessMailOnlyIfMaxRetryCountExceeded { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ public class GenericServiceConfigurationModel : IAmConfigurationModelWithResolut
public string RestoredMessage { get; set; }
[JsonProperty(PropertyName = "maxRetryCount")]
public int MaxRetryCount { get; set; } = 2;
[JsonProperty(PropertyName = "sendSuccessMailOnlyIfMaxRetryCountExceeded")]
public bool SendSuccessMailOnlyIfMaxRetryCountExceeded { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class WebWatcherConfigurationModel : IAmConfigurationModelWithResolution
public object Body { get; set; } = null;
[JsonProperty(PropertyName = "headers")]
public IDictionary<string, string> Headers { get; set; }
[JsonProperty(PropertyName = "sendSuccessMailOnlyIfMaxRetryCountExceeded")]
public bool SendSuccessMailOnlyIfMaxRetryCountExceeded { get; set; } = false;
}

public enum HttpCallApiMethod
Expand Down
10 changes: 9 additions & 1 deletion Elfo.Wardein.Watchers/WardeinWatcherWithResolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected virtual async Task PerformActionOnServiceAlive(WatcherStatusResult wat
try
{
log.Debug($"{GetLoggingDisplayName} is active");
if (!watcherStatusResult.PreviousStatus)
if (HasToSendMailOnServiceAlive(watcherStatusResult))
{
log.Debug($"Send Restored Notification for {GetLoggingDisplayName}");
await notificationService.SendNotificationAsync(Config.RecipientAddresses, Config.RestoredMessage,
Expand All @@ -63,5 +63,13 @@ await notificationService.SendNotificationAsync(Config.RecipientAddresses, Confi
log.Error(ex, $"Unable to send email from {GetLoggingDisplayName} watcher");
}
}

protected virtual bool HasToSendMailOnServiceAlive(WatcherStatusResult watcherStatusResult)
{
if (Config.SendSuccessMailOnlyIfMaxRetryCountExceeded)
return watcherStatusResult.FailureCount > Config.MaxRetryCount;
else
return !watcherStatusResult.PreviousStatus;
}
}
}

0 comments on commit d4d58c2

Please sign in to comment.