Lae/app/Jobs/Host/ScanAllHostsJob.php

48 lines
1008 B
PHP
Raw Normal View History

2022-11-08 09:46:00 +00:00
<?php
2023-01-13 10:42:05 +00:00
namespace App\Jobs\Host;
2022-11-08 09:46:00 +00:00
use App\Models\Host;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
2022-11-08 13:01:43 +00:00
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
2022-11-08 09:46:00 +00:00
2023-01-13 10:42:05 +00:00
// use Illuminate\Support\Facades\Log;
class ScanAllHostsJob implements ShouldQueue
2022-11-08 09:46:00 +00:00
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
2022-12-11 12:59:17 +00:00
public function handle(): void
2022-11-08 09:46:00 +00:00
{
2023-01-18 18:35:13 +00:00
// 扫描全部主机
Host::with('module')->chunk(100, function ($hosts) {
2022-11-08 09:46:00 +00:00
foreach ($hosts as $host) {
2022-11-23 03:10:36 +00:00
// 忽略维护中的模块
if ($host->module->status !== 'up') {
continue;
}
2023-01-13 10:42:05 +00:00
$host->updateOrDelete();
2022-11-08 09:46:00 +00:00
}
});
}
}