diff --git a/Server/application/command.php b/Server/application/command.php index 15eaed5f..5bb55f27 100644 --- a/Server/application/command.php +++ b/Server/application/command.php @@ -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', // 同步内容库 √ ]; diff --git a/Server/application/command/SyncContentCommand.php b/Server/application/command/SyncContentCommand.php new file mode 100644 index 00000000..401b0070 --- /dev/null +++ b/Server/application/command/SyncContentCommand.php @@ -0,0 +1,34 @@ +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("同步任务推送失败"); + } + } +} \ No newline at end of file diff --git a/Server/application/job/SyncContentJob.php b/Server/application/job/SyncContentJob.php new file mode 100644 index 00000000..8f2b9b4f --- /dev/null +++ b/Server/application/job/SyncContentJob.php @@ -0,0 +1,34 @@ +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(); + } + } + } +} \ No newline at end of file