Lae/app/Jobs/Host/DeleteHostJob.php

63 lines
1.8 KiB
PHP
Raw Normal View History

2022-09-03 06:01:51 +00:00
<?php
2023-01-13 14:11:56 +00:00
namespace App\Jobs\Host;
2022-09-03 06:01:51 +00:00
use App\Models\Host;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
2022-11-06 11:28:22 +00:00
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
2022-09-08 16:12:02 +00:00
// use Illuminate\Contracts\Queue\ShouldBeUnique;
2022-09-03 06:01:51 +00:00
class DeleteHostJob implements ShouldQueue
2022-09-03 06:01:51 +00:00
{
2022-09-08 16:12:02 +00:00
use InteractsWithQueue, Queueable, SerializesModels;
2022-09-03 06:01:51 +00:00
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
2022-12-11 12:59:17 +00:00
public function handle(): void
2022-09-03 06:01:51 +00:00
{
2022-12-11 12:59:17 +00:00
// 查找暂停时间超过 3 天的 host
2023-01-10 13:42:27 +00:00
(new Host)->where('status', 'suspended')->where('suspended_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
2022-09-03 06:01:51 +00:00
foreach ($hosts as $host) {
2023-01-13 14:11:56 +00:00
dispatch(new HostJob($host, 'delete'));
2022-09-03 06:01:51 +00:00
}
});
2022-11-16 02:29:50 +00:00
// 查找部署时间超过 3 天以上的 host
2023-01-10 13:42:27 +00:00
(new Host)->where('status', 'pending')->where('created_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
foreach ($hosts as $host) {
2023-01-13 14:11:56 +00:00
dispatch(new HostJob($host, 'delete'));
}
});
// 查找不可用时间超过 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'));
}
});
// 查找锁定时间超过 3 天以上的 host
(new Host)->where('status', 'locked')->where('locked_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
foreach ($hosts as $host) {
dispatch(new HostJob($host, 'delete'));
}
});
2022-09-03 06:01:51 +00:00
}
}