evaluationRunId); if (! $run || $run->isCanceled()) { return; } $coordinator = new EvaluationCoordinator(); try { $ruleSet = EvaluationRuleSet::find($run->rule_set_id); if (! $ruleSet) { $coordinator->eventError($run, 'Working set nelze připravit: chybí ruleset.', [ 'step' => 'build_working_set', 'round_id' => $run->round_id, ]); return; } $coordinator->eventInfo($run, 'Working set: krok spuštěn.', [ 'step' => 'build_working_set', 'round_id' => $run->round_id, ]); $run->update([ 'status' => 'RUNNING', 'current_step' => 'build_working_set', 'progress_total' => 0, 'progress_done' => 0, ]); WorkingQso::where('evaluation_run_id', $run->id)->delete(); $logIds = Log::where('round_id', $run->round_id)->pluck('id'); $logOverrides = LogOverride::where('evaluation_run_id', $run->id)->get()->keyBy('log_id'); $ignoredLogIds = $logOverrides ->filter(fn ($override) => $override->forced_log_status === 'IGNORED') ->keys() ->all(); if ($ignoredLogIds) { $logIds = $logIds->reject(fn ($id) => in_array($id, $ignoredLogIds, true))->values(); } $total = $logIds->isEmpty() ? 0 : LogQso::whereIn('log_id', $logIds)->count(); $run->update([ 'progress_total' => $total, 'progress_done' => 0, ]); $coordinator->eventInfo($run, 'Příprava working setu.', [ 'step' => 'build_working_set', 'round_id' => $run->round_id, 'step_progress_done' => 0, 'step_progress_total' => $total, ]); $jobs = []; foreach ($logIds as $logId) { $jobs[] = new BuildWorkingSetLogJob($run->id, (int) $logId); } $next = function () use ($run) { Bus::chain([ new PauseEvaluationRunJob( $run->id, 'WAITING_REVIEW_INPUT', 'waiting_review_input', 'Čeká na kontrolu vstupů.' ), ])->onQueue('evaluation')->dispatch(); }; if (! $jobs) { $next(); return; } $batch = Bus::batch($jobs) ->then($next) ->onQueue('evaluation') ->dispatch(); $run->update(['batch_id' => $batch->id]); } catch (Throwable $e) { $coordinator->eventError($run, 'Working set: krok selhal.', [ 'step' => 'build_working_set', 'round_id' => $run->round_id, 'error' => $e->getMessage(), ]); throw $e; } } }