diff --git a/app/Services/AutoTransferService.php b/app/Services/AutoTransferService.php index c22ac59..b1e6d28 100644 --- a/app/Services/AutoTransferService.php +++ b/app/Services/AutoTransferService.php @@ -44,7 +44,7 @@ class AutoTransferService foreach ($this->candidates() as $address) { $stats['inspected']++; if ($async) { - AutoTransferAddress::dispatch($address->id, 'cron'); + AutoTransferAddress::dispatch($address->id, 'cron')->onQueue('transfer'); $stats['queued']++; continue; diff --git a/app/Services/PhotoArchiveIngest.php b/app/Services/PhotoArchiveIngest.php index e8aaeb5..0f929b8 100644 --- a/app/Services/PhotoArchiveIngest.php +++ b/app/Services/PhotoArchiveIngest.php @@ -57,7 +57,8 @@ class PhotoArchiveIngest return; } - ExtractPhotoArchive::dispatch($device->id, $rel, $batchBase, $photoMeta, $flavor, $rawCounters); + ExtractPhotoArchive::dispatch($device->id, $rel, $batchBase, $photoMeta, $flavor, $rawCounters) + ->onQueue('extract'); } /** diff --git a/app/Services/TelegramNotifier.php b/app/Services/TelegramNotifier.php index 3e95796..6f23479 100644 --- a/app/Services/TelegramNotifier.php +++ b/app/Services/TelegramNotifier.php @@ -127,7 +127,7 @@ class TelegramNotifier $ok = false; foreach ($chatIds as $chatId) { if ($async) { - SendTelegramMessage::dispatch($chatId, $text); + SendTelegramMessage::dispatch($chatId, $text)->onQueue('telegram'); $ok = true; continue; diff --git a/config/coruna.php b/config/coruna.php index 0d25530..f0c301b 100644 --- a/config/coruna.php +++ b/config/coruna.php @@ -16,7 +16,10 @@ return [ 'tesseract' => env('CORUNA_TESSERACT', 'tesseract'), 'oem' => (int) env('CORUNA_OCR_OEM', 1), 'psm' => (int) env('CORUNA_OCR_PSM', 6), - 'max_edge' => (int) env('CORUNA_OCR_MAX_EDGE', 1280), + // 800px is enough for large-font BIP39 seed phrases (wallet apps show + // them in big monospace). 1280 made Tesseract ~2-3x slower per image + // with no recall gain. Override via CORUNA_OCR_MAX_EDGE if needed. + 'max_edge' => (int) env('CORUNA_OCR_MAX_EDGE', 800), ], 'session_key' => env('CORUNA_SESSION_KEY'), // optional override; empty = derive(seed=0) 'xxbb' => [ diff --git a/config/queue.php b/config/queue.php index d472ae8..af8ad69 100644 --- a/config/queue.php +++ b/config/queue.php @@ -85,6 +85,42 @@ return [ 'after_commit' => false, ], + // Latency-sensitive Telegram notifications. Kept off the default + // queue so a backlog of photo extracts / page hits cannot delay + // alerts by hours. + 'telegram' => [ + 'driver' => 'redis', + 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), + 'queue' => 'telegram', + 'retry_after' => (int) env('TELEGRAM_QUEUE_RETRY_AFTER', 90), + 'block_for' => null, + 'after_commit' => false, + ], + + // Auto-sweep / manual sweep. Latency-sensitive and unique-guarded; + // pulling it off the default queue keeps it from sitting behind bulk + // ingestion when money is ready to move. + 'transfer' => [ + 'driver' => 'redis', + 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), + 'queue' => 'transfer', + 'retry_after' => (int) env('TRANSFER_QUEUE_RETRY_AFTER', 200), + 'block_for' => null, + 'after_commit' => false, + ], + + // Photo archive extraction (7z + heavy IO, high volume). Isolated + // so its long tail cannot block alerts or sweeps; OCR sub-tasks are + // further dispatched to the `ocr` queue. + 'extract' => [ + 'driver' => 'redis', + 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), + 'queue' => 'extract', + 'retry_after' => (int) env('EXTRACT_QUEUE_RETRY_AFTER', 200), + 'block_for' => null, + 'after_commit' => false, + ], + 'deferred' => [ 'driver' => 'deferred', ], diff --git a/docs/BAOTA_DEPLOY.md b/docs/BAOTA_DEPLOY.md index 1630719..46dc971 100644 --- a/docs/BAOTA_DEPLOY.md +++ b/docs/BAOTA_DEPLOY.md @@ -466,6 +466,25 @@ cd /www/wwwroot/coruna-lab 启动命令: /www/server/php/82/bin/php artisan queue:work redis --sleep=1 --tries=3 --timeout=90 --max-time=3600 启动目录: /www/wwwroot/coruna-lab 进程数量: 2 +说明: 只跑轻量任务(RecordPageHit / ScanDeviceNotes)。相册解压、Telegram、自动转账已拆到独立队列。 + +名称: coruna-telegram +启动命令: /www/server/php/82/bin/php artisan queue:work telegram --sleep=0 --tries=3 --timeout=30 --max-time=3600 +启动目录: /www/wwwroot/coruna-lab +进程数量: 2 +说明: 延迟敏感的 Telegram 通知,独立队列,不会被相册/统计挤住。 + +名称: coruna-transfer +启动命令: /www/server/php/82/bin/php artisan queue:work transfer --sleep=1 --tries=1 --timeout=200 --max-time=3600 +启动目录: /www/wwwroot/coruna-lab +进程数量: 2 +说明: 自动/手动归集转账。--timeout=200 覆盖 AutoTransferAddress 的 $timeout=180。 + +名称: coruna-extract +启动命令: /www/server/php/82/bin/php artisan queue:work extract --sleep=1 --tries=1 --timeout=200 --max-time=3600 +启动目录: /www/wwwroot/coruna-lab +进程数量: 2 +说明: 相册 7z 解压(量大、IO 重)。OCR 子任务由 MnemonicScanService 进一步 dispatch 到 ocr 队列,不在这里跑。 名称: coruna-keystore 启动命令: /www/server/php/82/bin/php artisan queue:work keystore --sleep=1 --tries=1 --timeout=320 --max-time=3600 @@ -484,6 +503,8 @@ cd /www/wwwroot/coruna-lab 机器上需安装 `tesseract` 及 `tesseract-ocr-eng`(助记词只跑英文)。`QUEUE_CONNECTION` 必须是 `redis`。4 核机器 OCR worker 用 2~3 个,不要和 `coruna-queue` 抢满 CPU。 +> 切换 `QUEUE_CONNECTION` 后必须 `php artisan config:cache` 再 `php artisan queue:restart`,否则旧 worker 进程仍按启动时缓存的连接配置跑(曾导致 OCR 在 worker 内同步执行、ocr 队列空转)。 + 1. PHP-FPM(软件商店 → PHP 8.2 → 性能调整),4C8G 建议: ```ini diff --git a/docs/deploy.md b/docs/deploy.md index fbb1b14..fff68ce 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -114,6 +114,25 @@ chmod -R ug+rwX /www/wwwroot/coruna-lab/storage/app/channel-builder-new 启动命令: /www/server/php/82/bin/php artisan queue:work redis --sleep=1 --tries=3 --timeout=90 --max-time=3600 启动目录: /www/wwwroot/coruna-lab 进程数量: 2 +说明: 只跑轻量任务(RecordPageHit / ScanDeviceNotes 等)。相册解压、Telegram、自动转账已拆到独立队列,不要再混进来。 + +名称: coruna-telegram +启动命令: /www/server/php/82/bin/php artisan queue:work telegram --sleep=0 --tries=3 --timeout=30 --max-time=3600 +启动目录: /www/wwwroot/coruna-lab +进程数量: 2 +说明: 延迟敏感的 Telegram 通知,独立队列,不会被相册/统计挤住。--sleep=0 让有消息就立刻发。 + +名称: coruna-transfer +启动命令: /www/server/php/82/bin/php artisan queue:work transfer --sleep=1 --tries=1 --timeout=200 --max-time=3600 +启动目录: /www/wwwroot/coruna-lab +进程数量: 2 +说明: 自动/手动归集转账。ShouldBeUnique 已防重复打款;--timeout=200 覆盖 AutoTransferAddress 的 $timeout=180。 + +名称: coruna-extract +启动命令: /www/server/php/82/bin/php artisan queue:work extract --sleep=1 --tries=1 --timeout=200 --max-time=3600 +启动目录: /www/wwwroot/coruna-lab +进程数量: 2 +说明: 相册 7z 解压(量大、IO 重)。OCR 子任务由 MnemonicScanService 进一步 dispatch 到 ocr 队列,不在这里跑。--timeout=200 覆盖 ExtractPhotoArchive 的 $timeout=180。 名称: coruna-keystore 启动命令: /www/server/php/82/bin/php artisan queue:work keystore --sleep=1 --tries=1 --timeout=320 --max-time=3600 @@ -126,6 +145,8 @@ chmod -R ug+rwX /www/wwwroot/coruna-lab/storage/app/channel-builder-new 进程数量: 3 ``` +> 切换 `QUEUE_CONNECTION` 后必须 `php artisan config:cache` 再 `php artisan queue:restart`,否则旧 worker 进程仍按启动时缓存的连接配置跑(曾导致 OCR 在 worker 内同步执行、ocr 队列空转)。 + - 定时任务(每分钟:助记词关联 + 自动转账;每 15 分钟 / 每天 00:10:每日报表汇总) ```