feat : ali
This commit is contained in:
@@ -10,14 +10,57 @@ 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: "* * * * *", name: "OssDelByDisableTask", singleton: true , callback: "execute", memo: "这是一个示例的定时任务")]
|
||||
#[Crontab(rule: "0 5 * * *", name: "OssDelByDisableTask", singleton: true , callback: "execute", memo: "定时删除未使用的oss资源")]
|
||||
class OssDelByDisableTask
|
||||
{
|
||||
public function execute()
|
||||
/**
|
||||
* 日志
|
||||
* @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
|
||||
{
|
||||
//todo Write logic
|
||||
var_dump(date('Y-m-d H:i:s', time()));
|
||||
$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__.'异步删除昨日无效图片');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user