66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* This crontab file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cron\Oss;
|
|
|
|
use App\Cache\Redis\Common\CommonRedisKey;
|
|
use App\Cache\Redis\RedisCache;
|
|
use App\Extend\DateUtil;
|
|
use App\Lib\Log;
|
|
use App\Model\OssObject;
|
|
use Hyperf\Crontab\Annotation\Crontab;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
use RedisException;
|
|
|
|
#[Crontab(rule: "0 5 * * *", name: "OssDelByDisableTask", singleton: true , callback: "execute", memo: "定时删除未使用的oss资源")]
|
|
class OssDelByDisableTask
|
|
{
|
|
/**
|
|
* 日志
|
|
* @var Log $log
|
|
*/
|
|
#[Inject]
|
|
protected Log $log;
|
|
|
|
/**
|
|
* 缓存
|
|
* @var RedisCache $redis
|
|
*/
|
|
#[Inject]
|
|
protected RedisCache $redis;
|
|
|
|
/**
|
|
* @return void
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
* @throws RedisException
|
|
*/
|
|
public function execute(): void
|
|
{
|
|
$ossObjectModel = new OssObject();
|
|
|
|
$time = date('Y-m-d H:i:s',time() - DateUtil::DAY);
|
|
$list = $ossObjectModel->getOssIdListByIsEnabled($time);
|
|
|
|
if (empty($list)){
|
|
$this->log->notice(__CLASS__.'昨日没有无效的资源');
|
|
return;
|
|
}
|
|
|
|
|
|
foreach ($list->toArray() as $item) {
|
|
$this->redis->lPush(CommonRedisKey::getDeleteOssImgListByOssId(), (string)$item,'system');
|
|
}
|
|
|
|
$this->log->notice(__CLASS__.'异步删除昨日无效图片');
|
|
}
|
|
} |