File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
ServiceControl.Audit.Persistence.RavenDb5
ServiceControl.Audit.Persistence.Tests.RavenDb5 Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 33 using System ;
44 using System . Threading ;
55 using System . Threading . Tasks ;
6+ using NServiceBus . Logging ;
67 using Raven . Client . Documents ;
8+ using Raven . Client . Exceptions . Database ;
79
810 class RavenDbEmbeddedPersistenceLifecycle : IRavenDbPersistenceLifecycle
911 {
@@ -26,7 +28,21 @@ public async Task Start(CancellationToken cancellationToken)
2628 {
2729 database = EmbeddedDatabase . Start ( databaseConfiguration ) ;
2830
29- documentStore = await database . Connect ( cancellationToken ) . ConfigureAwait ( false ) ;
31+ while ( true )
32+ {
33+ cancellationToken . ThrowIfCancellationRequested ( ) ;
34+
35+ try
36+ {
37+ documentStore = await database . Connect ( cancellationToken ) . ConfigureAwait ( false ) ;
38+ return ;
39+ }
40+ catch ( DatabaseLoadTimeoutException e )
41+ {
42+ Log . Warn ( "Could not connect to database. Retrying in 500ms..." , e ) ;
43+ await Task . Delay ( 500 , cancellationToken ) . ConfigureAwait ( false ) ;
44+ }
45+ }
3046 }
3147
3248 public Task Stop ( CancellationToken cancellationToken )
@@ -39,7 +55,7 @@ public Task Stop(CancellationToken cancellationToken)
3955
4056 IDocumentStore documentStore ;
4157 EmbeddedDatabase database ;
42-
58+ static readonly ILog Log = LogManager . GetLogger ( typeof ( RavenDbEmbeddedPersistenceLifecycle ) ) ;
4359 readonly DatabaseConfiguration databaseConfiguration ;
4460 }
45- }
61+ }
Original file line number Diff line number Diff line change 66 using System . Net . NetworkInformation ;
77 using System . Threading ;
88 using System . Threading . Tasks ;
9+ using NServiceBus . Logging ;
910 using NUnit . Framework ;
1011 using ServiceControl . Audit . Persistence . RavenDb ;
1112
@@ -41,8 +42,9 @@ public static async Task<EmbeddedDatabase> GetInstance(CancellationToken cancell
4142
4243 return embeddedDatabase ;
4344 }
44- catch ( Exception )
45+ catch ( Exception e )
4546 {
47+ Log . Warn ( "Could not connect to database. Retrying in 500ms..." , e ) ;
4648 await Task . Delay ( 500 , cancellationToken ) . ConfigureAwait ( false ) ;
4749 }
4850 }
@@ -87,5 +89,6 @@ static int FindAvailablePort(int startPort)
8789
8890 static EmbeddedDatabase embeddedDatabase ;
8991 static SemaphoreSlim semaphoreSlim = new SemaphoreSlim ( 1 , 1 ) ;
92+ static readonly ILog Log = LogManager . GetLogger ( typeof ( SharedEmbeddedServer ) ) ;
9093 }
9194}
You can’t perform that action at this time.
0 commit comments