增加 队列暂停
This commit is contained in:
parent
456e26748d
commit
8c28e45c98
47
app/Jobs/Host/SuspendOverdueHosts.php
Normal file
47
app/Jobs/Host/SuspendOverdueHosts.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?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
|
||||||
|
{
|
||||||
|
if (!$this->host) {
|
||||||
|
Host::where('next_due_at', '<', now())
|
||||||
|
->where('status', '!=', 'suspended')
|
||||||
|
->chunk(100, function ($hosts) {
|
||||||
|
foreach ($hosts as $host) {
|
||||||
|
dispatch(new self($host));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->host?->suspend();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user