Files
lgp-admin-plus-api/app/Jobs/SyncOssObjectsJob.php
LQ bcf54c2727 初始化
缺陷:主题配色需要优化整体的同风格
2026-08-14 23:21:21 +08:00

51 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Jobs;
use App\Service\MaterialService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
/**
* OSS 对象同步任务
*
* 同步本身是同步接口(前端点一次跑一批),这个 Job 只是把同一个 Service 方法
* 包成可入队的形式bucket 里几万个对象时不该让人一直点按钮,
* 以后把队列驱动切成 redis 就能 dispatch 它自己跑完全量。
* 这里不改任何队列配置,默认驱动下 dispatch 等于同步执行。
*/
class SyncOssObjectsJob implements ShouldQueue
{
use Queueable;
/**
* @param array $params 与 MaterialService::syncFromOss 同构oss_config_id / prefix / marker / limit
*/
public function __construct(public array $params = [])
{
}
/**
* 一路续拉到 finished
*
* next_marker 跟上一轮一样说明驱动没有推进(配置或权限异常),必须跳出,
* 否则这里会变成一个不停打 OSS 的死循环。
*/
public function handle(): void
{
cc_set_time_limit();
$service = MaterialService::getInstance();
$params = $this->params;
$marker = (string) ($params['marker'] ?? '');
while (true) {
$params['marker'] = $marker;
$result = $service->syncFromOss($params);
$next = (string) ($result['next_marker'] ?? '');
if ((bool) ($result['finished'] ?? true) || $next === '' || $next === $marker) {
break;
}
$marker = $next;
}
}
}