This commit is contained in:
柳清爽
2025-04-21 17:09:56 +08:00
3 changed files with 69 additions and 0 deletions

View File

@@ -19,4 +19,5 @@ return [
'message:friendsList' => 'app\command\MessageFriendsListCommand', // 微信好友消息列表 √
'message:chatroomList' => 'app\command\MessageChatroomListCommand', // 微信群聊消息列表 √
'department:list' => 'app\command\DepartmentListCommand', // 部门列表 √
'content:sync' => 'app\command\SyncContentCommand', // 同步内容库 √
];

View File

@@ -0,0 +1,34 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Queue;
class SyncContentCommand extends Command
{
protected function configure()
{
$this->setName('content:sync')
->setDescription('同步内容库数据');
}
protected function execute(Input $input, Output $output)
{
// 将任务推送到队列
$jobHandlerClassName = 'app\job\SyncContentJob';
$jobData = [
'time' => time(),
'type' => 'sync_content'
];
$isPushed = Queue::push($jobHandlerClassName, $jobData);
if ($isPushed !== false) {
$output->writeln("同步任务已推送到队列");
} else {
$output->writeln("同步任务推送失败");
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace app\job;
use think\queue\Job;
class SyncContentJob
{
public function fire(Job $job, $data)
{
try {
// TODO: 在这里实现具体的同步逻辑
// 1. 获取需要同步的数据
// 2. 处理数据
// 3. 更新到目标位置
// 如果任务执行成功,删除任务
$job->delete();
// 记录日志
\think\Log::info('内容库同步成功:' . json_encode($data));
} catch (\Exception $e) {
// 如果任务执行失败,记录日志
\think\Log::error('内容库同步失败:' . $e->getMessage());
// 如果任务失败次数小于3次重新放入队列
if ($job->attempts() < 3) {
$job->release(60); // 延迟60秒后重试
} else {
$job->delete();
}
}
}
}