Skip to content

Commit 1e8060e

Browse files
author
Greg Bielleman
committed
Merge pull request #422 from Particular/Issue-416
@indualagarsamy based on your testing feedback I'm merging :) Thanks for your help
2 parents 68ad7ec + 4a4a33c commit 1e8060e

File tree

8 files changed

+190
-201
lines changed

8 files changed

+190
-201
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
namespace ServiceControl.CustomChecks
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Reactive.Concurrency;
6+
using System.Reactive.Linq;
7+
using NServiceBus;
8+
using NServiceBus.Logging;
9+
using Raven.Abstractions.Data;
10+
using Raven.Client;
11+
using INeedInitialization = NServiceBus.INeedInitialization;
12+
13+
public class CustomCheckNotifications : INeedInitialization, IWantToRunWhenBusStartsAndStops, IObserver<IndexChangeNotification>
14+
{
15+
IDocumentStore store;
16+
IBus bus;
17+
int lastCount;
18+
IDisposable subscription;
19+
ILog logging = LogManager.GetLogger(typeof(CustomCheckNotifications));
20+
21+
public CustomCheckNotifications()
22+
{
23+
// Need this because INeedInitialization does not use DI instead use Activator.CreateInstance
24+
}
25+
26+
public CustomCheckNotifications(IDocumentStore store, IBus bus)
27+
{
28+
this.bus = bus;
29+
this.store = store;
30+
}
31+
32+
public void Init()
33+
{
34+
Configure.Component<CustomCheckNotifications>(DependencyLifecycle.SingleInstance);
35+
}
36+
37+
public void OnNext(IndexChangeNotification value)
38+
{
39+
UpdateCount();
40+
}
41+
42+
void UpdateCount()
43+
{
44+
try
45+
{
46+
using (var session = store.OpenSession())
47+
{
48+
var failedCustomCheckCount = session.Query<CustomCheck, CustomChecksIndex>().Count(p => p.Status == Status.Fail);
49+
if (lastCount == failedCustomCheckCount)
50+
return;
51+
lastCount = failedCustomCheckCount;
52+
bus.Publish(new CustomChecksUpdated
53+
{
54+
Failed = lastCount
55+
});
56+
}
57+
}
58+
catch (Exception ex)
59+
{
60+
logging.WarnFormat("Failed to emit CustomCheckUpdated - {0}", ex);
61+
}
62+
63+
}
64+
65+
public void OnError(Exception error)
66+
{
67+
//Ignore
68+
}
69+
70+
public void OnCompleted()
71+
{
72+
//Ignore
73+
}
74+
75+
public void Start()
76+
{
77+
subscription = store.Changes().ForIndex("CustomChecksIndex").SubscribeOn(Scheduler.Default).Subscribe(this);
78+
}
79+
80+
public void Stop()
81+
{
82+
subscription.Dispose();
83+
}
84+
}
85+
}

src/ServiceControl/CustomChecks/CustomChecksComputation.cs

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/ServiceControl/CustomChecks/RaiseCustomCheckChanges.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
namespace ServiceControl.MessageFailures
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Reactive.Concurrency;
6+
using System.Reactive.Linq;
7+
using NServiceBus;
8+
using NServiceBus.Logging;
9+
using Raven.Abstractions.Data;
10+
using Raven.Client;
11+
using ServiceControl.Contracts.MessageFailures;
12+
using ServiceControl.MessageFailures.Api;
13+
using INeedInitialization = NServiceBus.INeedInitialization;
14+
15+
public class FailedMessageViewIndexNotifications : INeedInitialization, IWantToRunWhenBusStartsAndStops, IObserver<IndexChangeNotification>
16+
{
17+
IBus bus;
18+
IDocumentStore store;
19+
int lastCount;
20+
IDisposable subscription;
21+
ILog logging = LogManager.GetLogger(typeof(FailedMessageViewIndexNotifications));
22+
23+
public FailedMessageViewIndexNotifications()
24+
{
25+
// Need this because INeedInitialization does not use DI instead use Activator.CreateInstance
26+
}
27+
28+
public FailedMessageViewIndexNotifications(IDocumentStore store, IBus bus)
29+
{
30+
this.bus = bus;
31+
this.store = store;
32+
}
33+
34+
public void OnNext(IndexChangeNotification value)
35+
{
36+
UpdatedCount();
37+
}
38+
39+
public void OnError(Exception error)
40+
{
41+
//Ignore
42+
}
43+
44+
public void OnCompleted()
45+
{
46+
//Ignore
47+
}
48+
49+
void UpdatedCount()
50+
{
51+
try
52+
{
53+
using (var session = store.OpenSession())
54+
{
55+
var failedMessageCount = session.Query<FailedMessage, FailedMessageViewIndex>().Count(p => p.Status == FailedMessageStatus.Unresolved);
56+
if (lastCount == failedMessageCount)
57+
return;
58+
lastCount = failedMessageCount;
59+
bus.Publish(new MessageFailuresUpdated
60+
{
61+
Total = failedMessageCount
62+
});
63+
}
64+
}
65+
catch(Exception ex)
66+
{
67+
logging.WarnFormat("Failed to emit MessageFailuresUpdated - {0}", ex);
68+
}
69+
}
70+
71+
public void Init()
72+
{
73+
Configure.Component<FailedMessageViewIndexNotifications>(DependencyLifecycle.SingleInstance);
74+
}
75+
76+
public void Start()
77+
{
78+
subscription = store.Changes().ForIndex("FailedMessageViewIndex").SubscribeOn(Scheduler.Default).Subscribe(this);
79+
}
80+
81+
public void Stop()
82+
{
83+
subscription.Dispose();
84+
}
85+
}
86+
}

src/ServiceControl/MessageFailures/Handlers/RaiseMessageFailuresChanges.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/ServiceControl/MessageFailures/MessageFailuresComputation.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)