no message

This commit is contained in:
kuaifan 2025-03-03 11:59:02 +08:00
parent 684bf12a5c
commit 8c7b0c502d
4 changed files with 38 additions and 14 deletions

View File

@ -22,7 +22,7 @@ class SyncDialogUserMsgToElasticsearch extends Command
protected $signature = 'elasticsearch:sync-dialog-user-msg {--f} {--i} {--c} {--batch=500}'; protected $signature = 'elasticsearch:sync-dialog-user-msg {--f} {--i} {--c} {--batch=500}';
protected $description = '同步聊天会话用户和消息到Elasticsearch'; protected $description = '同步聊天会话用户和消息到Elasticsearch';
protected $elasticsearch; protected $es;
/** /**
* SyncDialogUserMsgToElasticsearch constructor. * SyncDialogUserMsgToElasticsearch constructor.
@ -30,7 +30,7 @@ class SyncDialogUserMsgToElasticsearch extends Command
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->elasticsearch = new ElasticSearch(ElasticSearch::DUM); $this->es = new ElasticSearch(ElasticSearch::DUM);
} }
/** /**
@ -44,11 +44,12 @@ class SyncDialogUserMsgToElasticsearch extends Command
// 清除索引 // 清除索引
if ($this->option('c')) { if ($this->option('c')) {
$this->info('清除索引...'); $this->info('清除索引...');
if (!$this->elasticsearch->indexExists()) { if (!$this->es->indexExists()) {
$this->saveLastId(true);
$this->info('索引不存在'); $this->info('索引不存在');
return 0; return 0;
} }
$result = $this->elasticsearch->deleteIndex(); $result = $this->es->deleteIndex();
if (isset($result['error'])) { if (isset($result['error'])) {
$this->error('删除索引失败: ' . $result['error']); $this->error('删除索引失败: ' . $result['error']);
return 1; return 1;
@ -59,13 +60,14 @@ class SyncDialogUserMsgToElasticsearch extends Command
} }
// 判断创建索引 // 判断创建索引
if (!$this->elasticsearch->indexExists()) { if (!$this->es->indexExists()) {
$this->info('创建索引...'); $this->info('创建索引...');
$result = $this->elasticsearch->createDialogUserMsgIndex(); $result = $this->es->createDialogUserMsgIndex();
if (isset($result['error'])) { if (isset($result['error'])) {
$this->error('创建索引失败: ' . $result['error']); $this->error('创建索引失败: ' . $result['error']);
return 1; return 1;
} }
$this->saveLastId(true);
$this->info('索引创建成功'); $this->info('索引创建成功');
} }
@ -151,7 +153,7 @@ class SyncDialogUserMsgToElasticsearch extends Command
} }
if ($params['body']) { if ($params['body']) {
$result = $this->elasticsearch->bulk($params); $result = $this->es->bulk($params);
if (isset($result['errors']) && $result['errors']) { if (isset($result['errors']) && $result['errors']) {
$this->error('批量索引用户数据部分失败'); $this->error('批量索引用户数据部分失败');
Log::error('Elasticsearch批量索引失败: ' . json_encode($result['items'])); Log::error('Elasticsearch批量索引失败: ' . json_encode($result['items']));
@ -230,7 +232,7 @@ class SyncDialogUserMsgToElasticsearch extends Command
$chunks = array_chunk($params['body'], 1000); $chunks = array_chunk($params['body'], 1000);
foreach ($chunks as $chunk) { foreach ($chunks as $chunk) {
$chunkParams = ['body' => $chunk]; $chunkParams = ['body' => $chunk];
$result = $this->elasticsearch->bulk($chunkParams); $result = $this->es->bulk($chunkParams);
if (isset($result['errors']) && $result['errors']) { if (isset($result['errors']) && $result['errors']) {
$this->error('批量索引消息数据部分失败'); $this->error('批量索引消息数据部分失败');
Log::error('Elasticsearch批量索引失败: ' . json_encode($result['items'])); Log::error('Elasticsearch批量索引失败: ' . json_encode($result['items']));

28
cmd
View File

@ -416,10 +416,30 @@ if [ $# -gt 0 ]; then
rm -rf vendor rm -rf vendor
rm -rf composer.lock rm -rf composer.lock
fi fi
mkdir -p "${cur_path}/docker/log/supervisor" # 目录权限
mkdir -p "${cur_path}/docker/mysql/data" volumes=(
chmod -R 775 "${cur_path}/docker/log/supervisor" "docker/log/supervisor"
chmod -R 775 "${cur_path}/docker/mysql/data" "docker/mysql/data"
"docker/office/logs"
"docker/office/data"
"docker/es/data"
)
cmda=""
cmdb=""
for vol in "${volumes[@]}"; do
mkdir -p "${cur_path}/${vol}"
chmod -R 775 "${cur_path}/${vol}"
rm -f "${cur_path}/${vol}/dootask.lock"
cmda="${cmda} -v ./${vol}:/usr/share/${vol}"
cmdb="${cmdb} touch /usr/share/${vol}/dootask.lock &&"
done
docker run --rm ${cmda} nginx:alpine sh -c "${cmdb} touch /usr/share/docker/dootask.lock"
for vol in "${volumes[@]}"; do
if [ ! -f "${cur_path}/${vol}/dootask.lock" ]; then
error "目录【${vol}】权限不足!"
exit 1
fi
done
# 启动容器 # 启动容器
[[ "$(arg_get port)" -gt 0 ]] && env_set APP_PORT "$(arg_get port)" [[ "$(arg_get port)" -gt 0 ]] && env_set APP_PORT "$(arg_get port)"
$COMPOSE up php -d $COMPOSE up php -d

View File

@ -1 +1,2 @@
*/ *
!.gitignore

View File

@ -1 +1,2 @@
*/ *
!.gitignore