检查 主机是否存在

This commit is contained in:
iVampireSP.com 2022-11-08 17:46:00 +08:00
parent ac0b0da416
commit ec99867379
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 50 additions and 0 deletions

View File

@ -8,6 +8,7 @@
use App\Jobs\Remote\FetchModule;
use App\Jobs\Remote\PushWorkOrder;
use App\Jobs\CheckAndChargeBalance;
use App\Jobs\CheckHostIfExistsOnModule;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@ -34,6 +35,8 @@ protected function schedule(Schedule $schedule)
$schedule->job(new DeleteHost())->hourly();
$schedule->job(new CheckHostIfExistsOnModule())->hourly()->withoutOverlapping()->onOneServer();
$schedule->job(new CheckAndChargeBalance())->everyFiveMinutes()->onOneServer()->withoutOverlapping();
}

View File

@ -0,0 +1,47 @@
<?php
namespace App\Jobs;
use App\Models\Host;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Http;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
class CheckHostIfExistsOnModule implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
Host::with('module')->chunk(100, function ($hosts) {
foreach ($hosts as $host) {
$http = Http::remote($host->module->api_token, $host->module->url);
$response = $http->get('hosts/' . $host->id);
if ($response->status() === 404) {
dispatch(new \App\Jobs\Remote\Host($host, 'delete'));
}
}
});
}
}