检查 主机是否存在
This commit is contained in:
parent
ac0b0da416
commit
ec99867379
@ -8,6 +8,7 @@
|
|||||||
use App\Jobs\Remote\FetchModule;
|
use App\Jobs\Remote\FetchModule;
|
||||||
use App\Jobs\Remote\PushWorkOrder;
|
use App\Jobs\Remote\PushWorkOrder;
|
||||||
use App\Jobs\CheckAndChargeBalance;
|
use App\Jobs\CheckAndChargeBalance;
|
||||||
|
use App\Jobs\CheckHostIfExistsOnModule;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
@ -34,6 +35,8 @@ protected function schedule(Schedule $schedule)
|
|||||||
|
|
||||||
$schedule->job(new DeleteHost())->hourly();
|
$schedule->job(new DeleteHost())->hourly();
|
||||||
|
|
||||||
|
$schedule->job(new CheckHostIfExistsOnModule())->hourly()->withoutOverlapping()->onOneServer();
|
||||||
|
|
||||||
$schedule->job(new CheckAndChargeBalance())->everyFiveMinutes()->onOneServer()->withoutOverlapping();
|
$schedule->job(new CheckAndChargeBalance())->everyFiveMinutes()->onOneServer()->withoutOverlapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
47
app/Jobs/CheckHostIfExistsOnModule.php
Normal file
47
app/Jobs/CheckHostIfExistsOnModule.php
Normal 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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user