fix(队列&seeder): 修复队列超时和文档创建问题

- 修复队列超时问题:
  - 将 queue:listen 改为 queue:work,提高性能和稳定性
  - 增加超时时间从 300 秒到 600 秒,确保大文件转换任务有足够时间
  - 同时更新 dev 和 dev-octane 脚本

- 修复 DatabaseSeeder 文档创建问题:
  - 不再使用 factory 创建文档,避免生成不存在的文件路径
  - 直接使用 Document::create() 明确指定所有字段
  - 所有文档状态设置为 pending,表示等待转换
  - 使用 UUID 生成唯一文件路径,便于管理
This commit is contained in:
2026-03-12 14:37:15 +08:00
parent 704d1225e6
commit 0fb9b1938d
2 changed files with 108 additions and 18 deletions

View File

@@ -55,11 +55,11 @@
],
"dev": [
"Composer\\Config::disableProcessTimeout",
"npx concurrently -c \"#93c5fd,#c4b5fd,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --queue=documents,default --tries=3 --timeout=300\" \"npm run dev\" --names=server,queue,vite --kill-others"
"npx concurrently -c \"#93c5fd,#c4b5fd,#fdba74\" \"php artisan serve\" \"php artisan queue:work --queue=documents,default --tries=3 --timeout=600\" \"npm run dev\" --names=server,queue,vite --kill-others"
],
"dev-octane": [
"Composer\\Config::disableProcessTimeout",
"npx concurrently -c \"#93c5fd,#c4b5fd,#fdba74\" \"php artisan octane:start --watch\" \"php artisan queue:listen --queue=documents,default --tries=3 --timeout=300\" \"npm run dev\" --names=octane,queue,vite --kill-others"
"npx concurrently -c \"#93c5fd,#c4b5fd,#fdba74\" \"php artisan octane:start --watch\" \"php artisan queue:work --queue=documents,default --tries=3 --timeout=600\" \"npm run dev\" --names=octane,queue,vite --kill-others"
],
"octane:start": [
"@php artisan octane:start"

View File

@@ -99,117 +99,207 @@ class DatabaseSeeder extends Seeder
// 赵六属于人力资源部
$user4->groups()->attach($hrGroup->id);
// 5. 创建全局文档
// 5. 创建全局文档(仅元数据,不创建实际文件)
$this->command->info('创建全局文档...');
Document::factory()->global()->create([
Document::create([
'title' => '公司员工手册',
'description' => '包含公司规章制度、员工福利、考勤制度等重要信息',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '员工手册_2024.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'global',
'group_id' => null,
'uploaded_by' => $admin->id,
'conversion_status' => 'pending',
]);
Document::factory()->global()->create([
Document::create([
'title' => '办公室使用规范',
'description' => '办公室设施使用规范和注意事项',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '办公室规范.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'global',
'group_id' => null,
'uploaded_by' => $admin->id,
'conversion_status' => 'pending',
]);
Document::factory()->global()->create([
Document::create([
'title' => '公司年度总结报告',
'description' => '2024年度公司发展总结和2025年规划',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '年度总结_2024.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'global',
'group_id' => null,
'uploaded_by' => $admin->id,
'conversion_status' => 'pending',
]);
Document::factory()->global()->create([
Document::create([
'title' => '安全管理制度',
'description' => '公司信息安全和物理安全管理制度',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '安全管理制度.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'global',
'group_id' => null,
'uploaded_by' => $admin->id,
'conversion_status' => 'pending',
]);
// 6. 创建技术部专用文档
$this->command->info('创建技术部专用文档...');
Document::factory()->dedicated($techGroup->id)->create([
Document::create([
'title' => '系统架构设计文档',
'description' => '公司核心系统的架构设计和技术选型说明',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '系统架构设计.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $techGroup->id,
'uploaded_by' => $user1->id,
'conversion_status' => 'pending',
]);
Document::factory()->dedicated($techGroup->id)->create([
Document::create([
'title' => '代码规范指南',
'description' => '团队代码编写规范和最佳实践',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '代码规范.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $techGroup->id,
'uploaded_by' => $admin->id,
'conversion_status' => 'pending',
]);
Document::factory()->dedicated($techGroup->id)->create([
Document::create([
'title' => '数据库设计文档',
'description' => '数据库表结构设计和关系说明',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '数据库设计.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $techGroup->id,
'uploaded_by' => $user2->id,
'conversion_status' => 'pending',
]);
Document::factory()->dedicated($techGroup->id)->create([
Document::create([
'title' => 'API 接口文档',
'description' => '系统对外提供的 API 接口说明和使用示例',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => 'API接口文档.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $techGroup->id,
'uploaded_by' => $user1->id,
'conversion_status' => 'pending',
]);
// 7. 创建市场部专用文档
$this->command->info('创建市场部专用文档...');
Document::factory()->dedicated($marketGroup->id)->create([
Document::create([
'title' => '市场推广方案',
'description' => '2025年第一季度市场推广计划和预算',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '市场推广方案_Q1.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $marketGroup->id,
'uploaded_by' => $user3->id,
'conversion_status' => 'pending',
]);
Document::factory()->dedicated($marketGroup->id)->create([
Document::create([
'title' => '品牌宣传策略',
'description' => '品牌定位和宣传渠道策略',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '品牌宣传策略.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $marketGroup->id,
'uploaded_by' => $admin->id,
'conversion_status' => 'pending',
]);
Document::factory()->dedicated($marketGroup->id)->create([
Document::create([
'title' => '客户调研报告',
'description' => '目标客户群体调研分析报告',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '客户调研报告.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $marketGroup->id,
'uploaded_by' => $user3->id,
'conversion_status' => 'pending',
]);
// 8. 创建人力资源部专用文档
$this->command->info('创建人力资源部专用文档...');
Document::factory()->dedicated($hrGroup->id)->create([
Document::create([
'title' => '招聘流程指南',
'description' => '公司招聘流程和面试评估标准',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '招聘流程指南.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $hrGroup->id,
'uploaded_by' => $user4->id,
'conversion_status' => 'pending',
]);
Document::factory()->dedicated($hrGroup->id)->create([
Document::create([
'title' => '员工培训计划',
'description' => '2025年员工培训计划和课程安排',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '员工培训计划_2025.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $hrGroup->id,
'uploaded_by' => $admin->id,
'conversion_status' => 'pending',
]);
Document::factory()->dedicated($hrGroup->id)->create([
Document::create([
'title' => '薪酬福利制度',
'description' => '公司薪酬结构和福利政策说明',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '薪酬福利制度.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $hrGroup->id,
'uploaded_by' => $user4->id,
'conversion_status' => 'pending',
]);
Document::factory()->dedicated($hrGroup->id)->create([
Document::create([
'title' => '绩效考核标准',
'description' => '员工绩效考核指标和评估流程',
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
'file_name' => '绩效考核标准.docx',
'file_size' => fake()->numberBetween(100000, 500000),
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'type' => 'dedicated',
'group_id' => $hrGroup->id,
'uploaded_by' => $admin->id,
'conversion_status' => 'pending',
]);
$this->command->info('演示数据生成完成!');