|
31 | 31 |
|
32 | 32 | /** |
33 | 33 | * Service for managing extension scans. |
34 | | - * |
| 34 | + * <p> |
35 | 35 | * Owns scan lifecycle (STARTED → VALIDATING → SCANNING → PASSED/QUARANTINED), |
36 | 36 | * runs validation checks, and submits scanner jobs via JobRunr. |
37 | 37 | */ |
@@ -181,23 +181,10 @@ public void runValidation( |
181 | 181 |
|
182 | 182 | /** |
183 | 183 | * Submit long-running scanner jobs for an extension version. |
184 | | - * |
185 | | - * This method: |
186 | | - * 1. Gets all registered scanners from the registry |
187 | | - * 2. Creates ScanJob records in QUEUED status |
188 | | - * 3. Enqueues each scanner invocation to JobRunr for parallel execution |
189 | | - * 4. Transitions the ExtensionScan to SCANNING status |
190 | | - * 5. Returns the scan ID for tracking |
191 | | - * |
192 | | - * The scan ID is the ExtensionScan.id which links |
193 | | - * the high-level scan record with individual ScanJob records. |
194 | | - * |
195 | | - * IMPORTANT: ScanJob records are created BEFORE JobRunr jobs are enqueued. |
196 | | - * This avoids a race condition where AsyncScanCompletionService checks for |
197 | | - * scan jobs before the JobRunr handler has created them. |
198 | | - * |
199 | | - * JobRunr handles parallel execution, automatic retry, and persistence. |
200 | | - * AsyncScanCompletionService will activate extensions when all scans complete. |
| 184 | + * <p> |
| 185 | + * Flow: transition scan to SCANNING, then for each scanner create a ScanJob (QUEUED) |
| 186 | + * and try to enqueue a JobRunr request. On enqueue failure we only log since the watchdog |
| 187 | + * will re-enqueue them for retry. |
201 | 188 | */ |
202 | 189 | public boolean submitScannerJobs(@Nonnull ExtensionScan scan, @Nonnull ExtensionVersion extVersion) { |
203 | 190 | if (!config.isEnabled()) { |
@@ -225,54 +212,46 @@ public boolean submitScannerJobs(@Nonnull ExtensionScan scan, @Nonnull Extension |
225 | 212 | // Transition to SCANNING status before submitting jobs |
226 | 213 | transitionTo(scan, ScanStatus.SCANNING); |
227 | 214 |
|
228 | | - // Create ScanJob records and enqueue JobRunr jobs |
229 | 215 | int enqueuedCount = 0; |
230 | | - for (Scanner scannerDef : scanners) { |
| 216 | + |
| 217 | + for (Scanner scanner : scanners) { |
| 218 | + String scannerType = scanner.getScannerType(); |
| 219 | + |
| 220 | + ScannerJob job = new ScannerJob(); |
| 221 | + job.setScanId(scanId); |
| 222 | + job.setScannerType(scannerType); |
| 223 | + job.setExtensionVersionId(extensionVersionId); |
| 224 | + job.setStatus(ScannerJob.JobStatus.QUEUED); |
| 225 | + job.setCreatedAt(LocalDateTime.now()); |
| 226 | + job.setUpdatedAt(LocalDateTime.now()); |
| 227 | + job.setPollLeaseUntil(null); |
| 228 | + job.setPollAttempts(0); |
| 229 | + job.setRecoveryInProgress(false); |
| 230 | + scanJobRepository.save(job); |
| 231 | + |
| 232 | + logger.debug("Created ScanJob record: {} for {} (scanId={})", |
| 233 | + scannerType, NamingUtil.toLogFormat(extVersion), scanId); |
| 234 | + |
231 | 235 | try { |
232 | | - String scannerType = scannerDef.getScannerType(); |
233 | | - |
234 | | - // Create ScanJob record FIRST (before enqueuing to JobRunr) |
235 | | - // This ensures AsyncScanCompletionService can find the job records |
236 | | - // even if it runs before the JobRunr handler executes |
237 | | - ScannerJob job = new ScannerJob(); |
238 | | - job.setScanId(scanId); |
239 | | - job.setScannerType(scannerType); |
240 | | - job.setExtensionVersionId(extensionVersionId); |
241 | | - job.setStatus(ScannerJob.JobStatus.QUEUED); |
242 | | - job.setCreatedAt(LocalDateTime.now()); |
243 | | - job.setUpdatedAt(LocalDateTime.now()); |
244 | | - job.setPollLeaseUntil(null); |
245 | | - job.setPollAttempts(0); |
246 | | - job.setRecoveryInProgress(false); |
247 | | - scanJobRepository.save(job); |
248 | | - |
249 | | - logger.debug("Created ScanJob record: {} for {} (scanId={})", |
250 | | - scannerType, NamingUtil.toLogFormat(extVersion), scanId); |
251 | | - |
252 | | - // Now enqueue to JobRunr - the handler will find the existing ScanJob |
253 | 236 | ScannerInvocationRequest jobRequest = new ScannerInvocationRequest( |
254 | | - scannerType, |
255 | | - extensionVersionId, |
256 | | - scanId |
257 | | - ); |
258 | | - |
| 237 | + scannerType, extensionVersionId, scanId); |
| 238 | + |
259 | 239 | jobScheduler.enqueue(jobRequest); |
260 | 240 | enqueuedCount++; |
261 | | - |
262 | | - logger.debug("Enqueued scanner job: {} for {} (scanId={})", |
| 241 | + |
| 242 | + logger.debug("Enqueued scanner job: {} for {} (scanId={})", |
263 | 243 | scannerType, NamingUtil.toLogFormat(extVersion), scanId); |
264 | | - |
| 244 | + |
265 | 245 | } catch (Exception e) { |
266 | | - logger.error("Failed to enqueue scanner {} for scanId={}", |
267 | | - scannerDef.getScannerType(), scanId, e); |
268 | | - // Continue with other scanners even if one fails to enqueue |
| 246 | + logger.error("Failed to enqueue scanner {} for scanId={}: {}. ", |
| 247 | + scannerType, scanId, e.getMessage(), e); |
269 | 248 | } |
270 | 249 | } |
271 | | - |
| 250 | + |
272 | 251 | logger.debug("Enqueued {} of {} scanner jobs for: {} (scanId={})", |
273 | 252 | enqueuedCount, scanners.size(), NamingUtil.toLogFormat(extVersion), scanId); |
274 | | - |
275 | | - return enqueuedCount > 0; |
| 253 | + |
| 254 | + return true; |
276 | 255 | } |
277 | 256 |
|
278 | 257 | /** |
|
0 commit comments