Initial commit

This commit is contained in:
Zdeněk Burda
2026-01-09 21:26:40 +01:00
parent e83aec6dca
commit 41e3ce6f25
404 changed files with 61250 additions and 28 deletions

View File

@@ -0,0 +1,95 @@
<?php
namespace App\Jobs;
use App\Models\EvaluationRun;
use App\Models\LogResult;
use App\Services\Evaluation\EvaluationCoordinator;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Bus;
use Throwable;
/**
* Job: DispatchAggregateResultsJobsJob
*
* Účel:
* - Rozdělí agregaci výsledků na menší joby podle log_id.
* - Spustí batch jobů AggregateLogResultsJob a po dokončení naváže
* ApplyLogOverridesJob + RecalculateOfficialRanksJob + PauseEvaluationRunJob.
*/
class DispatchAggregateResultsJobsJob implements ShouldQueue
{
use Queueable;
public int $tries = 2;
public array $backoff = [60];
public function __construct(
protected int $evaluationRunId
) {
}
public function handle(): void
{
$run = EvaluationRun::find($this->evaluationRunId);
if (! $run || $run->isCanceled()) {
return;
}
$coordinator = new EvaluationCoordinator();
try {
$coordinator->eventInfo($run, 'Aggregate: krok spuštěn.', [
'step' => 'aggregate',
'round_id' => $run->round_id,
]);
$logIds = LogResult::where('evaluation_run_id', $run->id)
->pluck('log_id')
->all();
$run->update([
'status' => 'RUNNING',
'current_step' => 'aggregate',
'progress_total' => count($logIds),
'progress_done' => 0,
]);
$jobs = [];
foreach ($logIds as $logId) {
$jobs[] = new AggregateLogResultsJob($run->id, (int) $logId);
}
$next = function () use ($run) {
Bus::chain([
new ApplyLogOverridesJob($run->id),
new RecalculateOfficialRanksJob($run->id),
new PauseEvaluationRunJob(
$run->id,
'WAITING_REVIEW_SCORE',
'waiting_review_score',
'Čeká na kontrolu skóre.'
),
])->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, 'Aggregate: krok selhal.', [
'step' => 'aggregate',
'round_id' => $run->round_id,
'error' => $e->getMessage(),
]);
throw $e;
}
}
}