Merge branch 'develop' of https://e.coding.net/g-xtcy5189/cunkebao/cunkebao_v3 into develop
This commit is contained in:
@@ -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', // 同步内容库 √
|
||||
];
|
||||
|
||||
34
Server/application/command/SyncContentCommand.php
Normal file
34
Server/application/command/SyncContentCommand.php
Normal 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("同步任务推送失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Server/application/job/SyncContentJob.php
Normal file
34
Server/application/job/SyncContentJob.php
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user