- 新增 MediaArchiveJob、MediaOssArchiveService、WechatMediaArchiveService 与回填命令 - Message/DataProcessing 等支持归档调度与持久化下载 URL - WebSocket 控制器整理;朋友圈与文档/定时任务说明更新 Made-with: Cursor
58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace app\job;
|
|
|
|
use app\common\service\WechatMediaArchiveService;
|
|
use think\facade\Config;
|
|
use think\facade\Log;
|
|
use think\queue\Job;
|
|
use think\Queue;
|
|
|
|
class MediaArchiveJob
|
|
{
|
|
const QUEUE_NAME = 'media_archive';
|
|
|
|
public function fire(Job $job, $data)
|
|
{
|
|
try {
|
|
$scope = $data['scope'] ?? '';
|
|
$id = (int)($data['id'] ?? 0);
|
|
if (empty($scope) || $id <= 0) {
|
|
$job->delete();
|
|
return;
|
|
}
|
|
|
|
$success = false;
|
|
if ($scope === 'message') {
|
|
$success = WechatMediaArchiveService::archiveMessageById($id);
|
|
} elseif ($scope === 'moment') {
|
|
$success = WechatMediaArchiveService::archiveMomentById($id);
|
|
}
|
|
|
|
if ($success || $job->attempts() >= 3) {
|
|
$job->delete();
|
|
return;
|
|
}
|
|
|
|
$job->release(Config::get('queue.failed_delay', 10));
|
|
} catch (\Exception $e) {
|
|
Log::error('媒体资源归档任务失败:' . $e->getMessage(), $data ?: []);
|
|
if ($job->attempts() >= 3) {
|
|
$job->delete();
|
|
} else {
|
|
$job->release(Config::get('queue.failed_delay', 10));
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function dispatch($scope, $id, array $extra = [])
|
|
{
|
|
$payload = array_merge($extra, [
|
|
'scope' => $scope,
|
|
'id' => (int)$id,
|
|
]);
|
|
|
|
return Queue::push(self::class, $payload, self::QUEUE_NAME);
|
|
}
|
|
}
|