File tree 3 files changed +25
-1
lines changed
3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ public record class GitHubSettings
47
47
48
48
public record class HangfireSettings
49
49
{
50
+ public int MaxInitializationAttempts { get ; set ; } = 5 ;
51
+ public int InitializationRetryDelaySeconds { get ; set ; } = 10 ;
52
+
50
53
public int ServerCheckIntervalMinutes { get ; set ; } = 15 ;
51
54
public int QueuePollIntervalSeconds { get ; set ; } = 30 ;
52
55
public int SchedulePollIntervalSeconds { get ; set ; } = 30 ;
Original file line number Diff line number Diff line change 7
7
using NLog . Config ;
8
8
using NLog . Extensions . Logging ;
9
9
using NLog . Targets ;
10
+ using Polly ;
11
+ using Polly . Retry ;
10
12
using Rubberduck . SmartIndenter ;
11
13
using RubberduckServices ;
12
14
using rubberduckvba . Server . Api . Admin ;
@@ -110,7 +112,25 @@ public static void Main(string[] args)
110
112
app . MapControllers ( ) ;
111
113
app . MapFallbackToFile ( "/index.html" ) ;
112
114
113
- StartHangfire ( app ) ;
115
+ var logger = app . Services . GetRequiredService < ILogger < Program > > ( ) ;
116
+ logger . LogInformation ( "App configuration completed. Starting hangfire..." ) ;
117
+
118
+ var hangfireOptions = app . Services . GetService < IOptions < HangfireSettings > > ( ) ? . Value ?? new ( ) ;
119
+ new ResiliencePipelineBuilder ( ) . AddRetry ( new RetryStrategyOptions
120
+ {
121
+ Delay = TimeSpan . FromSeconds ( 10 ) ,
122
+ MaxRetryAttempts = hangfireOptions . MaxInitializationAttempts ,
123
+ OnRetry = ( context ) =>
124
+ {
125
+ var retryCount = context . AttemptNumber ;
126
+ var delay = context . RetryDelay ;
127
+
128
+ logger . LogError ( context . Outcome . Exception , $ "Hangfire failed to start | Retrying storage connection in { delay . TotalSeconds } seconds. Attempt { retryCount } of { hangfireOptions . MaxInitializationAttempts } ") ;
129
+ return ValueTask . CompletedTask ;
130
+ }
131
+ } ) . Build ( ) . Execute ( ( ) => StartHangfire ( app ) ) ;
132
+
133
+ logger . LogInformation ( "Hangfire initialization completed. Starting application..." ) ;
114
134
app . Run ( ) ;
115
135
}
116
136
Original file line number Diff line number Diff line change 30
30
<PackageReference Include =" NLog.Extensions.Logging" Version =" 5.4.0" />
31
31
<PackageReference Include =" NLog.WindowsEventLog" Version =" 5.4.0" />
32
32
<PackageReference Include =" Octokit" Version =" 14.0.0" />
33
+ <PackageReference Include =" Polly" Version =" 8.5.2" />
33
34
<PackageReference Include =" Swashbuckle.AspNetCore" Version =" 7.2.0" />
34
35
<PackageReference Include =" System.IdentityModel.Tokens.Jwt" Version =" 8.3.1" />
35
36
</ItemGroup >
You can’t perform that action at this time.
0 commit comments