worker processes components from the jobs channel and sends results to the results channel
(jobs <-chan app.SnapshotComponent, results chan<- vsa.ComponentResult, ctx context.Context, data *validateVSAData)
| 431 | |
| 432 | // worker processes components from the jobs channel and sends results to the results channel |
| 433 | func worker(jobs <-chan app.SnapshotComponent, results chan<- vsa.ComponentResult, ctx context.Context, data *validateVSAData) { |
| 434 | // Create worker-specific fallback context once per worker |
| 435 | var workerFallbackContext *vsa.WorkerFallbackContext |
| 436 | var ctxErr error |
| 437 | |
| 438 | if data.fallbackToImageValidation && data.fallbackContext != nil { |
| 439 | var err error |
| 440 | workerFallbackContext, err = vsa.CreateWorkerFallbackContext(ctx, data.fallbackContext.FallbackPolicy) |
| 441 | if err != nil { |
| 442 | // Store the error but don't drain the channel - let other workers continue |
| 443 | ctxErr = fmt.Errorf("failed to create worker fallback context: %w", err) |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | // Process jobs with error handling that doesn't starve other workers |
| 448 | for component := range jobs { |
| 449 | var result vsa.ComponentResult |
| 450 | |
| 451 | if ctxErr != nil { |
| 452 | // If we have a context error, emit error for this specific job and continue |
| 453 | // Other workers can still process their share of jobs |
| 454 | result = vsa.ComponentResult{ |
| 455 | ComponentName: component.Name, |
| 456 | ImageRef: component.ContainerImage, |
| 457 | Error: ctxErr, |
| 458 | } |
| 459 | } else { |
| 460 | // Normal processing with worker context |
| 461 | result = processSnapshotComponentWithWorkerContext(ctx, component, data, workerFallbackContext) |
| 462 | } |
| 463 | |
| 464 | results <- result |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // validateSnapshotVSAsFromSpec processes components from a SnapshotSpec in parallel |
| 469 | // This is the unified processing path used by both --images and single identifier cases |