feat : ali

This commit is contained in:
2024-11-06 16:53:45 +08:00
parent 7b6f9e4aa7
commit 8d30a65528
9 changed files with 443 additions and 36 deletions

View File

@@ -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__.'异步删除昨日无效图片');
}
}