Refactor and enhance scanner worker functionality
- Cleaned up code formatting and organization across multiple files for improved readability. - Introduced `OsScanAnalyzerDispatcher` to handle OS analyzer execution and plugin loading. - Updated `ScanJobContext` to include an `Analysis` property for storing scan results. - Enhanced `ScanJobProcessor` to utilize the new `OsScanAnalyzerDispatcher`. - Improved logging and error handling in `ScanProgressReporter` for better traceability. - Updated project dependencies and added references to new analyzer plugins. - Revised task documentation to reflect current status and dependencies.
This commit is contained in:
		| @@ -1,65 +1,65 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Threading; | ||||
| using System.Threading.Tasks; | ||||
| using Microsoft.Extensions.Logging; | ||||
|  | ||||
| namespace StellaOps.Scanner.Worker.Processing; | ||||
|  | ||||
| public sealed class ScanJobProcessor | ||||
| { | ||||
|     private readonly IReadOnlyDictionary<string, IScanStageExecutor> _executors; | ||||
|     private readonly ScanProgressReporter _progressReporter; | ||||
|     private readonly ILogger<ScanJobProcessor> _logger; | ||||
|  | ||||
|     public ScanJobProcessor(IEnumerable<IScanStageExecutor> executors, ScanProgressReporter progressReporter, ILogger<ScanJobProcessor> logger) | ||||
|     { | ||||
|         _progressReporter = progressReporter ?? throw new ArgumentNullException(nameof(progressReporter)); | ||||
|         _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||
|  | ||||
|         var map = new Dictionary<string, IScanStageExecutor>(StringComparer.OrdinalIgnoreCase); | ||||
|         foreach (var executor in executors ?? Array.Empty<IScanStageExecutor>()) | ||||
|         { | ||||
|             if (executor is null || string.IsNullOrWhiteSpace(executor.StageName)) | ||||
|             { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             map[executor.StageName] = executor; | ||||
|         } | ||||
|  | ||||
|         foreach (var stage in ScanStageNames.Ordered) | ||||
|         { | ||||
|             if (map.ContainsKey(stage)) | ||||
|             { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             map[stage] = new NoOpStageExecutor(stage); | ||||
|             _logger.LogDebug("No executor registered for stage {Stage}; using no-op placeholder.", stage); | ||||
|         } | ||||
|  | ||||
|         _executors = map; | ||||
|     } | ||||
|  | ||||
|     public async ValueTask ExecuteAsync(ScanJobContext context, CancellationToken cancellationToken) | ||||
|     { | ||||
|         ArgumentNullException.ThrowIfNull(context); | ||||
|  | ||||
|         foreach (var stage in ScanStageNames.Ordered) | ||||
|         { | ||||
|             cancellationToken.ThrowIfCancellationRequested(); | ||||
|  | ||||
|             if (!_executors.TryGetValue(stage, out var executor)) | ||||
|             { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             await _progressReporter.ExecuteStageAsync( | ||||
|                 context, | ||||
|                 stage, | ||||
|                 executor.ExecuteAsync, | ||||
|                 cancellationToken).ConfigureAwait(false); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Threading; | ||||
| using System.Threading.Tasks; | ||||
| using Microsoft.Extensions.Logging; | ||||
|  | ||||
| namespace StellaOps.Scanner.Worker.Processing; | ||||
|  | ||||
| public sealed class ScanJobProcessor | ||||
| { | ||||
|     private readonly IReadOnlyDictionary<string, IScanStageExecutor> _executors; | ||||
|     private readonly ScanProgressReporter _progressReporter; | ||||
|     private readonly ILogger<ScanJobProcessor> _logger; | ||||
|  | ||||
|     public ScanJobProcessor(IEnumerable<IScanStageExecutor> executors, ScanProgressReporter progressReporter, ILogger<ScanJobProcessor> logger) | ||||
|     { | ||||
|         _progressReporter = progressReporter ?? throw new ArgumentNullException(nameof(progressReporter)); | ||||
|         _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||
|  | ||||
|         var map = new Dictionary<string, IScanStageExecutor>(StringComparer.OrdinalIgnoreCase); | ||||
|         foreach (var executor in executors ?? Array.Empty<IScanStageExecutor>()) | ||||
|         { | ||||
|             if (executor is null || string.IsNullOrWhiteSpace(executor.StageName)) | ||||
|             { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             map[executor.StageName] = executor; | ||||
|         } | ||||
|  | ||||
|         foreach (var stage in ScanStageNames.Ordered) | ||||
|         { | ||||
|             if (map.ContainsKey(stage)) | ||||
|             { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             map[stage] = new NoOpStageExecutor(stage); | ||||
|             _logger.LogDebug("No executor registered for stage {Stage}; using no-op placeholder.", stage); | ||||
|         } | ||||
|  | ||||
|         _executors = map; | ||||
|     } | ||||
|  | ||||
|     public async ValueTask ExecuteAsync(ScanJobContext context, CancellationToken cancellationToken) | ||||
|     { | ||||
|         ArgumentNullException.ThrowIfNull(context); | ||||
|  | ||||
|         foreach (var stage in ScanStageNames.Ordered) | ||||
|         { | ||||
|             cancellationToken.ThrowIfCancellationRequested(); | ||||
|  | ||||
|             if (!_executors.TryGetValue(stage, out var executor)) | ||||
|             { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             await _progressReporter.ExecuteStageAsync( | ||||
|                 context, | ||||
|                 stage, | ||||
|                 executor.ExecuteAsync, | ||||
|                 cancellationToken).ConfigureAwait(false); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user