diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index a6e864b..d31685f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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(); } diff --git a/app/Jobs/CheckHostIfExistsOnModule.php b/app/Jobs/CheckHostIfExistsOnModule.php new file mode 100644 index 0000000..f8db56b --- /dev/null +++ b/app/Jobs/CheckHostIfExistsOnModule.php @@ -0,0 +1,47 @@ +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')); + } + } + }); + } +}