Initial commit
This commit is contained in:
105
app/Jobs/DispatchUnpairedJobsJob.php
Normal file
105
app/Jobs/DispatchUnpairedJobsJob.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\EvaluationRun;
|
||||
use App\Models\WorkingQso;
|
||||
use App\Services\Evaluation\EvaluationCoordinator;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Job: DispatchUnpairedJobsJob
|
||||
*
|
||||
* Účel:
|
||||
* - Rozdělí klasifikaci nenapárovaných QSO do bucketů podle band_id + rcall_norm.
|
||||
* - Spustí batch jobů UnpairedClassificationBucketJob a po dokončení naváže
|
||||
* DuplicateResolutionJob.
|
||||
*/
|
||||
class DispatchUnpairedJobsJob implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public int $tries = 2;
|
||||
public array $backoff = [30];
|
||||
|
||||
public function __construct(
|
||||
protected int $evaluationRunId
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$run = EvaluationRun::find($this->evaluationRunId);
|
||||
if (! $run || $run->isCanceled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$coordinator = new EvaluationCoordinator();
|
||||
$coordinator->eventInfo($run, 'Dispatch unpaired: krok spuštěn.', [
|
||||
'step' => 'dispatch_unpaired',
|
||||
'round_id' => $run->round_id,
|
||||
]);
|
||||
|
||||
try {
|
||||
$buckets = WorkingQso::where('evaluation_run_id', $run->id)
|
||||
->whereNotNull('rcall_norm')
|
||||
->distinct()
|
||||
->get(['band_id', 'rcall_norm']);
|
||||
|
||||
$jobs = [];
|
||||
foreach ($buckets as $bucket) {
|
||||
$jobs[] = new UnpairedClassificationBucketJob(
|
||||
$run->id,
|
||||
$bucket->band_id !== null ? (int) $bucket->band_id : null,
|
||||
$bucket->rcall_norm
|
||||
);
|
||||
}
|
||||
|
||||
$run->refresh();
|
||||
$progressDone = (int) $run->progress_done;
|
||||
$progressTotal = $progressDone + count($jobs) + 1;
|
||||
$run->update([
|
||||
'progress_total' => $progressTotal,
|
||||
'progress_done' => $progressDone,
|
||||
]);
|
||||
|
||||
$next = function () use ($run) {
|
||||
Bus::chain([
|
||||
new DuplicateResolutionJob($run->id),
|
||||
new PauseEvaluationRunJob(
|
||||
$run->id,
|
||||
'WAITING_REVIEW_MATCH',
|
||||
'waiting_review_match',
|
||||
'Čeká na kontrolu matchingu.'
|
||||
),
|
||||
])->onQueue('evaluation')->dispatch();
|
||||
};
|
||||
|
||||
if (! $jobs) {
|
||||
$next();
|
||||
return;
|
||||
}
|
||||
|
||||
$batch = Bus::batch($jobs)
|
||||
->then($next)
|
||||
->onQueue('evaluation')
|
||||
->dispatch();
|
||||
$run->update(['batch_id' => $batch->id]);
|
||||
|
||||
$coordinator->eventInfo($run, 'Dispatch unpaired: krok dokončen.', [
|
||||
'step' => 'dispatch_unpaired',
|
||||
'round_id' => $run->round_id,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
$coordinator->eventError($run, 'Dispatch unpaired: krok selhal.', [
|
||||
'step' => 'dispatch_unpaired',
|
||||
'round_id' => $run->round_id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user