增加 扫描出错的主机

This commit is contained in:
iVampireSP.com 2023-03-04 18:21:08 +08:00
parent 612758adce
commit f560f03e77
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 37 additions and 1 deletions

View File

@ -4,7 +4,7 @@
use App\Jobs\Host\DeleteHostJob;
use App\Jobs\Host\DispatchHostCostQueueJob;
use App\Jobs\Host\ScanAllHostsJob;
use App\Jobs\Host\ScanErrorHostsJob;
use App\Jobs\Module\DispatchFetchModuleJob;
use App\Jobs\Module\SendModuleEarningsJob;
use App\Jobs\Subscription\DeleteDraftJob;
@ -49,6 +49,9 @@ protected function schedule(Schedule $schedule): void
// 检查主机是否存在于模块
// $schedule->job(new ScanAllHostsJob())->everyThirtyMinutes()->withoutOverlapping()->onOneServer()->name('检查主机是否存在于模块');
// 扫描出错的主机
$schedule->job(new ScanErrorHostsJob())->everyThirtyMinutes()->withoutOverlapping()->onOneServer()->name('扫描出错的主机');
// 检查未充值的订单,并充值
$schedule->job(new CheckAndChargeBalanceJob())->everyFiveMinutes()->onOneServer()->withoutOverlapping()->name('检查未充值的订单,并充值');

View File

@ -0,0 +1,33 @@
<?php
namespace App\Jobs\Host;
use App\Models\Host;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ScanErrorHostsJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Execute the job.
*/
public function handle(): void
{
// 扫描出错的主机
(new Host)->whereIn('status', ['error', 'pending', 'unavailable'])->with('module')->chunk(100, function ($hosts) {
foreach ($hosts as $host) {
// 忽略维护中的模块
if ($host->module->status !== 'up') {
continue;
}
$host->updateOrDelete();
}
});
}
}