@@ -26,50 +26,64 @@ internal class AssemblyAnalysisService : IHostedService, IDisposable
26
26
private Task _analysisTask ;
27
27
private bool _disposed ;
28
28
private bool _analysisScheduled ;
29
+ private ILogger _logger ;
29
30
30
31
public AssemblyAnalysisService ( IEnvironment environment , WebJobsScriptHostService scriptHost , ILoggerFactory loggerFactory , IOptionsMonitor < StandbyOptions > standbyOptionsMonitor )
31
32
{
32
33
_environment = environment ;
33
34
_scriptHost = scriptHost ;
34
35
_loggerFactory = loggerFactory ;
35
36
_standbyOptionsMonitor = standbyOptionsMonitor ;
37
+ _logger = _loggerFactory . CreateLogger < AssemblyAnalysisService > ( ) ;
36
38
}
37
39
38
40
public Task StartAsync ( CancellationToken cancellationToken )
39
41
{
40
- if ( ! _environment . IsCoreTools ( ) )
42
+ try
41
43
{
42
- if ( _standbyOptionsMonitor . CurrentValue . InStandbyMode )
44
+ if ( ! _environment . IsCoreTools ( ) )
43
45
{
44
- _standbyOptionsMonitor . OnChange ( standbyOptions =>
46
+ if ( _standbyOptionsMonitor . CurrentValue . InStandbyMode )
45
47
{
46
- if ( ! standbyOptions . InStandbyMode && ! _analysisScheduled )
48
+ _standbyOptionsMonitor . OnChange ( standbyOptions =>
47
49
{
48
- ScheduleAssemblyAnalysis ( ) ;
49
- }
50
- } ) ;
51
- }
52
- else
53
- {
54
- ScheduleAssemblyAnalysis ( ) ;
50
+ if ( ! standbyOptions . InStandbyMode && ! _analysisScheduled )
51
+ {
52
+ ScheduleAssemblyAnalysis ( ) ;
53
+ }
54
+ } ) ;
55
+ }
56
+ else
57
+ {
58
+ ScheduleAssemblyAnalysis ( ) ;
59
+ }
55
60
}
56
61
}
62
+ catch ( Exception ex )
63
+ {
64
+ _logger . LogError ( ex , "Error starting Assembly analysis service. Handling error and continuing." ) ;
65
+ }
57
66
58
67
return Task . CompletedTask ;
59
68
}
60
69
61
70
public Task StopAsync ( CancellationToken cancellationToken )
62
71
{
63
- _cancellationTokenSource ? . Cancel ( ) ;
64
-
65
- if ( _analysisTask != null && ! _analysisTask . IsCompleted )
72
+ try
66
73
{
67
- var logger = _loggerFactory . CreateLogger < AssemblyAnalysisService > ( ) ;
68
- logger . LogDebug ( "Assembly analysis service stopped before analysis completion. Waiting for cancellation." ) ;
74
+ _cancellationTokenSource ? . Cancel ( ) ;
69
75
70
- return _analysisTask ;
71
- }
76
+ if ( _analysisTask != null && ! _analysisTask . IsCompleted )
77
+ {
78
+ _logger . LogDebug ( "Assembly analysis service stopped before analysis completion. Waiting for cancellation." ) ;
72
79
80
+ return _analysisTask ;
81
+ }
82
+ }
83
+ catch ( Exception ex )
84
+ {
85
+ _logger . LogError ( ex , "Error stopping Assembly analysis service. Handling error and continuing." ) ;
86
+ }
73
87
return Task . CompletedTask ;
74
88
}
75
89
0 commit comments