修复 主机不会被删除的 bug

This commit is contained in:
iVampireSP.com 2023-02-05 01:10:30 +08:00
parent 3474e416b2
commit d3b5572076
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 8 additions and 6 deletions

View File

@ -48,7 +48,7 @@ public function handle(): void
// 查找不可用时间超过 3 天以上的 host
(new Host)->where('status', 'unavailable')->where('unavailable_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
foreach ($hosts as $host) {
dispatch(new HostJob($host, 'delete'));
dispatch(new HostJob($host, 'delete', false));
}
});

View File

@ -14,20 +14,22 @@ class HostJob implements ShouldQueue
{
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.
*
* @return void
*/
public function __construct(HostModel $host, $type = 'post')
public function __construct(HostModel $host, $type = 'post', $pass_unavailable = true)
{
//
$this->host = $host;
$this->type = $type;
$this->pass_unavailable = $pass_unavailable;
}
/**
@ -42,7 +44,7 @@ public function handle(): void
$host = $this->host;
// 忽略 unavailable 状态的 host
if ($host->status === 'unavailable') {
if (! $this->pass_unavailable && $host->status === 'unavailable') {
return;
}