68 lines
2 KiB
PHP
68 lines
2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use App\Services\Labs\DefinitionLab;
|
||
|
|
use App\Services\Labs\StockChaud;
|
||
|
|
use App\Services\OpenStack\FabriqueStack;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Support\Facades\Log;
|
||
|
|
use Throwable;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Construit une stack pour le stock chaud d'un lab (commandée par
|
||
|
|
* StockChaud::remplir). Mêmes règles de fiabilité que CreerStackLab :
|
||
|
|
* 3 essais, chaque essai raté supprime sa stack. Seule une stack
|
||
|
|
* CREATE_COMPLETE entre dans le stock.
|
||
|
|
*/
|
||
|
|
class CreerStackStock implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
|
||
|
|
public int $tries = 3;
|
||
|
|
|
||
|
|
/** @var array<int, int> */
|
||
|
|
public array $backoff = [15, 45];
|
||
|
|
|
||
|
|
public int $timeout = 280;
|
||
|
|
|
||
|
|
public function __construct(
|
||
|
|
private readonly string $lab,
|
||
|
|
private readonly string $base,
|
||
|
|
) {
|
||
|
|
$this->onQueue('stock');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function handle(FabriqueStack $fabrique, StockChaud $stock): void
|
||
|
|
{
|
||
|
|
$fabrique->nettoyerEssais($this->base);
|
||
|
|
|
||
|
|
$pret = $fabrique->fabriquer(DefinitionLab::depuis($this->lab), "{$this->base}-e{$this->attempts()}");
|
||
|
|
|
||
|
|
$stock->deposer($this->lab, $pret);
|
||
|
|
$stock->commandeTerminee($this->lab, $this->base);
|
||
|
|
$stock->reinitialiserEchecs($this->lab);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function failed(?Throwable $exception): void
|
||
|
|
{
|
||
|
|
$stock = app(StockChaud::class);
|
||
|
|
$stock->commandeTerminee($this->lab, $this->base);
|
||
|
|
$stock->compterEchec($this->lab);
|
||
|
|
|
||
|
|
Log::error("CreerStackStock : {$this->base} en échec après {$this->tries} essais", [
|
||
|
|
'raison' => $exception?->getMessage(),
|
||
|
|
]);
|
||
|
|
|
||
|
|
try {
|
||
|
|
app(FabriqueStack::class)->nettoyerEssais($this->base);
|
||
|
|
} catch (Throwable $e) {
|
||
|
|
Log::error("CreerStackStock : nettoyage impossible pour {$this->base}", ['raison' => $e->getMessage()]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|