Files
services_core/app/Jobs/CheckMikrotikConnection.php
T
2026-08-07 09:16:13 +07:00

45 lines
1.0 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\NasMikrotik;
use App\Services\Nas\MikrotikHealthService;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Throwable;
class CheckMikrotikConnection implements ShouldBeUnique, ShouldQueue
{
use Queueable;
public int $tries = 1;
public int $timeout = 25;
public int $uniqueFor = 240;
public function __construct(public int $mikrotikId)
{
$this->onQueue(config('nas.health.queue', 'nas-health'));
}
public function uniqueId(): string
{
return (string) $this->mikrotikId;
}
public function handle(MikrotikHealthService $health): void
{
$mikrotik = NasMikrotik::whereKey($this->mikrotikId)->where('status', 'active')->first();
if (! $mikrotik) {
return;
}
try {
$health->check($mikrotik);
} catch (Throwable) {
// Health service has persisted the offline state and next backoff time.
}
}
}