big update all menus
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\NasMikrotik;
|
||||
use App\Jobs\CheckMikrotikConnection;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CheckMikrotikConnections extends Command
|
||||
{
|
||||
protected $signature = 'nas:check-mikrotiks {--id=* : ID Mikrotik tertentu}';
|
||||
|
||||
protected $description = 'Mengantrekan pemeriksaan koneksi NAS yang sudah jatuh tempo';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$queued = 0;
|
||||
NasMikrotik::query()
|
||||
->where('status', 'active')
|
||||
->where(fn ($query) => $query->whereNull('next_health_check_at')->orWhere('next_health_check_at', '<=', now()))
|
||||
->when($this->option('id'), fn ($query) => $query->whereIn('id', $this->option('id')))
|
||||
->select(['id'])
|
||||
->chunkById(100, function ($devices) use (&$queued) {
|
||||
foreach ($devices as $index => $device) {
|
||||
CheckMikrotikConnection::dispatch($device->id)->delay(now()->addSeconds($index % 60));
|
||||
$queued++;
|
||||
}
|
||||
});
|
||||
$this->info("{$queued} pemeriksaan NAS masuk antrean nas-health.");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user