evaluationRunId); if (! $run || $run->isCanceled()) { return; } $coordinator = new EvaluationCoordinator(); $lock = null; $lockKey = "evaluation:parse:round:{$run->round_id}:log:{$this->logId}"; try { $lock = EvaluationLock::acquire( key: $lockKey, run: $run, ttl: 1800 ); if (! $lock) { throw new \RuntimeException("ParseLogJob nelze spustit – lock je držen (log_id={$this->logId})."); } $log = Log::with('file')->find($this->logId); if (! $log || (int) $log->round_id !== (int) $run->round_id) { return; } if (! $log->file || ! $log->file->path) { $coordinator->eventWarn($run, "Log #{$log->id} nemá soubor, parser přeskočen.", [ 'step' => 'parse_logs', 'round_id' => $run->round_id, 'log_id' => $log->id, ]); EvaluationRun::where('id', $run->id)->increment('progress_done'); return; } try { LogController::parseUploadedFile($log, $log->file->path); } catch (Throwable $e) { $coordinator->eventError($run, "Chyba parsování logu #{$log->id}: {$e->getMessage()}", [ 'step' => 'parse_logs', 'round_id' => $run->round_id, 'log_id' => $log->id, ]); } if ($run->rules_version === 'CLAIMED') { try { UpsertClaimedLogResultJob::dispatchSync($log->id); } catch (Throwable $e) { $coordinator->eventError($run, "Chyba deklarace výsledků logu #{$log->id}: {$e->getMessage()}", [ 'step' => 'claimed_upsert', 'round_id' => $run->round_id, 'log_id' => $log->id, ]); } } EvaluationRun::where('id', $run->id)->increment('progress_done'); $progressTotal = (int) ($run->progress_total ?? 0); $done = $progressTotal > 0 ? (int) EvaluationRun::where('id', $run->id)->value('progress_done') : 0; if ($progressTotal > 0 && $done % 10 === 0) { $coordinator->eventInfo($run, "Parsování logů: {$done}/{$progressTotal}", [ 'step' => 'parse_logs', 'round_id' => $run->round_id, 'step_progress_done' => $done, 'step_progress_total' => $progressTotal, ]); } } catch (Throwable $e) { $coordinator->eventError($run, "ParseLogJob selhal: {$e->getMessage()}", [ 'step' => 'parse_logs', 'round_id' => $run->round_id, 'log_id' => $this->logId, ]); throw $e; } finally { if ($lock) { EvaluationLock::release($lockKey, $run); } } } }