File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 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
4747
4848public record class HangfireSettings
4949{
50+ public int MaxInitializationAttempts { get ; set ; } = 5 ;
51+ public int InitializationRetryDelaySeconds { get ; set ; } = 10 ;
52+
5053 public int ServerCheckIntervalMinutes { get ; set ; } = 15 ;
5154 public int QueuePollIntervalSeconds { get ; set ; } = 30 ;
5255 public int SchedulePollIntervalSeconds { get ; set ; } = 30 ;
Original file line number Diff line number Diff line change 77using NLog . Config ;
88using NLog . Extensions . Logging ;
99using NLog . Targets ;
10+ using Polly ;
11+ using Polly . Retry ;
1012using Rubberduck . SmartIndenter ;
1113using RubberduckServices ;
1214using rubberduckvba . Server . Api . Admin ;
@@ -110,7 +112,25 @@ public static void Main(string[] args)
110112 app . MapControllers ( ) ;
111113 app . MapFallbackToFile ( "/index.html" ) ;
112114
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..." ) ;
114134 app . Run ( ) ;
115135 }
116136
Original file line number Diff line number Diff line change 3030 <PackageReference Include =" NLog.Extensions.Logging" Version =" 5.4.0" />
3131 <PackageReference Include =" NLog.WindowsEventLog" Version =" 5.4.0" />
3232 <PackageReference Include =" Octokit" Version =" 14.0.0" />
33+ <PackageReference Include =" Polly" Version =" 8.5.2" />
3334 <PackageReference Include =" Swashbuckle.AspNetCore" Version =" 7.2.0" />
3435 <PackageReference Include =" System.IdentityModel.Tokens.Jwt" Version =" 8.3.1" />
3536 </ItemGroup >
You can’t perform that action at this time.
0 commit comments