Paillasse/portail/app/Jobs/SupprimerStackLab.php

41 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Jobs;
use App\Models\LabSession;
use App\Services\OpenStack\HeatClient;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
/**
* Supprime la stack Heat d'une session de lab (étape 10) : fin de séance ou
* expiration automatique (voir routes/console.php, Schedule).
*/
class SupprimerStackLab implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 3;
public function __construct(private readonly LabSession $labSession)
{
$this->onQueue('sessions');
}
public function handle(HeatClient $heat): void
{
if ($this->labSession->heat_stack_name !== null) {
$heat->supprimerStack($this->labSession->heat_stack_name, $this->labSession->heat_stack_id);
}
$nouvelEtat = $this->labSession->expire_a !== null && $this->labSession->expire_a->isPast()
? LabSession::EXPIRE
: LabSession::TERMINE;
$this->labSession->forceFill(['etat' => $nouvelEtat])->save();
}
}