修复 主机不会被删除的 bug
This commit is contained in:
parent
3474e416b2
commit
d3b5572076
@ -48,7 +48,7 @@ public function handle(): void
|
|||||||
// 查找不可用时间超过 3 天以上的 host
|
// 查找不可用时间超过 3 天以上的 host
|
||||||
(new Host)->where('status', 'unavailable')->where('unavailable_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
|
(new Host)->where('status', 'unavailable')->where('unavailable_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
|
||||||
foreach ($hosts as $host) {
|
foreach ($hosts as $host) {
|
||||||
dispatch(new HostJob($host, 'delete'));
|
dispatch(new HostJob($host, 'delete', false));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -14,20 +14,22 @@ class HostJob implements ShouldQueue
|
|||||||
{
|
{
|
||||||
use InteractsWithQueue, Queueable, SerializesModels;
|
use InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
public HostModel $host;
|
protected HostModel $host;
|
||||||
|
|
||||||
public string $type;
|
protected string $type;
|
||||||
|
|
||||||
|
protected bool $pass_unavailable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(HostModel $host, $type = 'post')
|
public function __construct(HostModel $host, $type = 'post', $pass_unavailable = true)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
$this->pass_unavailable = $pass_unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,7 +44,7 @@ public function handle(): void
|
|||||||
$host = $this->host;
|
$host = $this->host;
|
||||||
|
|
||||||
// 忽略 unavailable 状态的 host
|
// 忽略 unavailable 状态的 host
|
||||||
if ($host->status === 'unavailable') {
|
if (! $this->pass_unavailable && $host->status === 'unavailable') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user