2023-02-12 18:46:45 +00:00
|
|
|
<?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 SuspendOverdueHosts implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected ?Host $host;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(?Host $host = null)
|
|
|
|
{
|
|
|
|
$this->host = $host;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle(): void
|
|
|
|
{
|
2023-02-12 19:12:26 +00:00
|
|
|
if (! $this->host) {
|
2023-02-12 19:06:27 +00:00
|
|
|
(new Host)->where('next_due_at', '<', now())
|
2023-02-12 18:46:45 +00:00
|
|
|
->where('status', '!=', 'suspended')
|
|
|
|
->chunk(100, function ($hosts) {
|
|
|
|
foreach ($hosts as $host) {
|
|
|
|
dispatch(new self($host));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->host?->suspend();
|
|
|
|
}
|
|
|
|
}
|