83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
||
|
||
namespace App\Jobs;
|
||
|
||
use App\Events\CertStatusUpdated;
|
||
use Illuminate\Bus\Queueable;
|
||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
use Illuminate\Foundation\Bus\Dispatchable;
|
||
use Illuminate\Queue\Queueable as QueueQueueable;
|
||
use Illuminate\Queue\SerializesModels;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use Illuminate\Support\Facades\Redis;
|
||
|
||
class SimulateCertIssue implements ShouldQueue
|
||
{
|
||
use Dispatchable, Queueable, SerializesModels;
|
||
|
||
public function __construct(
|
||
public string $domain,
|
||
public string $taskKey // z.B. "task:issue-cert:10.10.70.58"
|
||
) {}
|
||
|
||
public function handle(): void
|
||
{
|
||
// queued
|
||
event(new CertStatusUpdated(
|
||
id: $this->taskKey,
|
||
state: 'queued',
|
||
message: 'Erstellung gestartet…',
|
||
progress: 5,
|
||
meta: ['domain' => $this->domain, 'mode' => 'self-signed']
|
||
));
|
||
sleep(1);
|
||
|
||
// running – CSR
|
||
event(new CertStatusUpdated(
|
||
id: $this->taskKey,
|
||
state: 'running',
|
||
message: 'CSR wird erzeugt…',
|
||
progress: 20
|
||
));
|
||
sleep(1);
|
||
|
||
// running – Schlüssel
|
||
event(new CertStatusUpdated(
|
||
id: $this->taskKey,
|
||
state: 'running',
|
||
message: 'Schlüssel wird erstellt…',
|
||
progress: 55
|
||
));
|
||
sleep(1);
|
||
|
||
// running – signieren
|
||
event(new CertStatusUpdated(
|
||
id: $this->taskKey,
|
||
state: 'running',
|
||
message: 'Self-Signed wird signiert…',
|
||
progress: 85
|
||
));
|
||
sleep(1);
|
||
|
||
// done (FINAL)
|
||
event(new CertStatusUpdated(
|
||
id: $this->taskKey,
|
||
state: 'done',
|
||
message: "Zertifikat für {$this->domain} erstellt.",
|
||
progress: 100,
|
||
meta: ['final' => true, 'domain' => $this->domain]
|
||
));
|
||
|
||
// --- Aufräumen (verhindert doppelten Toast nach Reload) ---
|
||
// 1) Task-Detail entfernen
|
||
Cache::store('redis')->forget($this->taskKey);
|
||
// (Falls du zusätzlich unter "mailwolt_cache:{$this->taskKey}" speicherst, dann auch das:)
|
||
Cache::store('redis')->forget("mailwolt_cache:{$this->taskKey}");
|
||
|
||
// 2) User-Task-Set bereinigen (so hast du es gespeichert)
|
||
if (auth()->id()) {
|
||
Redis::srem('user:'.auth()->id().':tasks', $this->taskKey);
|
||
}
|
||
}
|
||
}
|