public void Handle(ReportCustomCheckResult message) { if (string.IsNullOrEmpty(message.EndpointName)) { throw new Exception("Received an custom check message without proper initialization of the EndpointName in the schema"); } if (string.IsNullOrEmpty(message.Host)) { throw new Exception("Received an custom check message without proper initialization of the Host in the schema"); } if (message.HostId == Guid.Empty) { throw new Exception("Received an custom check message without proper initialization of the HostId in the schema"); } var publish = false; var id = DeterministicGuid.MakeId(message.EndpointName, message.HostId.ToString(), message.CustomCheckId); CustomCheck customCheck; using (var session = store.OpenSession()) { customCheck = session.Load <CustomCheck>(id); if (customCheck == null || customCheck.Status == Status.Fail && !message.HasFailed || customCheck.Status == Status.Pass && message.HasFailed) { if (customCheck == null) { customCheck = new CustomCheck { Id = id }; } publish = true; } customCheck.CustomCheckId = message.CustomCheckId; customCheck.Category = message.Category; customCheck.Status = message.HasFailed ? Status.Fail : Status.Pass; customCheck.ReportedAt = message.ReportedAt; customCheck.FailureReason = message.FailureReason; customCheck.OriginatingEndpoint = new EndpointDetails { Host = message.Host, HostId = message.HostId, Name = message.EndpointName }; session.Store(customCheck); session.SaveChanges(); } if (publish) { if (message.HasFailed) { bus.Publish(new CustomCheckFailed { Id = id, CustomCheckId = message.CustomCheckId, Category = message.Category, FailedAt = message.ReportedAt, FailureReason = message.FailureReason, OriginatingEndpoint = customCheck.OriginatingEndpoint }); } else { bus.Publish(new CustomCheckSucceeded { Id = id, CustomCheckId = message.CustomCheckId, Category = message.Category, SucceededAt = message.ReportedAt, OriginatingEndpoint = customCheck.OriginatingEndpoint }); } } }
public async Task UpdateCustomCheckStatus(EndpointDetails originatingEndpoint, DateTime reportedAt, string customCheckId, string category, bool hasFailed, string failureReason) { var publish = false; var id = DeterministicGuid.MakeId(originatingEndpoint.Name, originatingEndpoint.HostId.ToString(), customCheckId); using (var session = store.OpenAsyncSession()) { var customCheck = await session.LoadAsync <CustomCheck>(id) .ConfigureAwait(false); if (customCheck == null || customCheck.Status == Status.Fail && !hasFailed || customCheck.Status == Status.Pass && hasFailed) { if (customCheck == null) { customCheck = new CustomCheck { Id = id }; } publish = true; } customCheck.CustomCheckId = customCheckId; customCheck.Category = category; customCheck.Status = hasFailed ? Status.Fail : Status.Pass; customCheck.ReportedAt = reportedAt; customCheck.FailureReason = failureReason; customCheck.OriginatingEndpoint = originatingEndpoint; await session.StoreAsync(customCheck) .ConfigureAwait(false); await session.SaveChangesAsync() .ConfigureAwait(false); } if (publish) { if (hasFailed) { await domainEvents.Raise(new CustomCheckFailed { Id = id, CustomCheckId = customCheckId, Category = category, FailedAt = reportedAt, FailureReason = failureReason, OriginatingEndpoint = originatingEndpoint }).ConfigureAwait(false); } else { await domainEvents.Raise(new CustomCheckSucceeded { Id = id, CustomCheckId = customCheckId, Category = category, SucceededAt = reportedAt, OriginatingEndpoint = originatingEndpoint }).ConfigureAwait(false); } } }
public async Task Handle(ReportCustomCheckResult message, IMessageHandlerContext context) { if (string.IsNullOrEmpty(message.EndpointName)) { throw new Exception("Received an custom check message without proper initialization of the EndpointName in the schema"); } if (string.IsNullOrEmpty(message.Host)) { throw new Exception("Received an custom check message without proper initialization of the Host in the schema"); } if (message.HostId == Guid.Empty) { throw new Exception("Received an custom check message without proper initialization of the HostId in the schema"); } var publish = false; var id = DeterministicGuid.MakeId(message.EndpointName, message.HostId.ToString(), message.CustomCheckId); CustomCheck customCheck; using (var session = store.OpenAsyncSession()) { customCheck = await session.LoadAsync <CustomCheck>(id) .ConfigureAwait(false); if (customCheck == null || customCheck.Status == Status.Fail && !message.HasFailed || customCheck.Status == Status.Pass && message.HasFailed) { if (customCheck == null) { customCheck = new CustomCheck { Id = id }; } publish = true; } customCheck.CustomCheckId = message.CustomCheckId; customCheck.Category = message.Category; customCheck.Status = message.HasFailed ? Status.Fail : Status.Pass; customCheck.ReportedAt = message.ReportedAt; customCheck.FailureReason = message.FailureReason; customCheck.OriginatingEndpoint = new EndpointDetails { Host = message.Host, HostId = message.HostId, Name = message.EndpointName }; await session.StoreAsync(customCheck) .ConfigureAwait(false); await session.SaveChangesAsync() .ConfigureAwait(false); } if (publish) { if (message.HasFailed) { await domainEvents.Raise(new CustomCheckFailed { Id = id, CustomCheckId = message.CustomCheckId, Category = message.Category, FailedAt = message.ReportedAt, FailureReason = message.FailureReason, OriginatingEndpoint = customCheck.OriginatingEndpoint }).ConfigureAwait(false); } else { await domainEvents.Raise(new CustomCheckSucceeded { Id = id, CustomCheckId = message.CustomCheckId, Category = message.Category, SucceededAt = message.ReportedAt, OriginatingEndpoint = customCheck.OriginatingEndpoint }).ConfigureAwait(false); } } }
public void Handle(ReportCustomCheckResult message) { if (string.IsNullOrEmpty(message.EndpointName)) { throw new ArgumentException("Received an custom check message without proper initialization of the EndpointName in the schema", "message.EndpointName"); } if (string.IsNullOrEmpty(message.Host)) { throw new ArgumentException("Received an custom check message without proper initialization of the Host in the schema", "message.Host"); } if (message.HostId == Guid.Empty) { throw new ArgumentException("Received an custom check message without proper initialization of the HostId in the schema", "message.HostId"); } var publish = false; var id = DeterministicGuid.MakeId(message.EndpointName, message.HostId.ToString(), message.CustomCheckId); var customCheck = Session.Load <CustomCheck>(id); if (customCheck == null || (customCheck.Status == Status.Fail && !message.HasFailed) || (customCheck.Status == Status.Pass && message.HasFailed)) { if (customCheck == null) { customCheck = new CustomCheck { Id = id, }; Session.Store(customCheck); } publish = true; } customCheck.CustomCheckId = message.CustomCheckId; customCheck.Category = message.Category; customCheck.Status = message.HasFailed ? Status.Fail : Status.Pass; customCheck.ReportedAt = message.ReportedAt; customCheck.FailureReason = message.FailureReason; customCheck.OriginatingEndpoint = new EndpointDetails { Host = message.Host, HostId = message.HostId, Name = message.EndpointName }; Session.Store(customCheck); if (publish) { if (message.HasFailed) { Bus.Publish <CustomCheckFailed>(m => { m.Id = id; m.CustomCheckId = message.CustomCheckId; m.Category = message.Category; m.FailedAt = message.ReportedAt; m.FailureReason = message.FailureReason; m.OriginatingEndpoint = customCheck.OriginatingEndpoint; }); } else { Bus.Publish <CustomCheckSucceeded>(m => { m.Id = id; m.CustomCheckId = message.CustomCheckId; m.Category = message.Category; m.SucceededAt = message.ReportedAt; m.OriginatingEndpoint = customCheck.OriginatingEndpoint; }); } } }