瀏覽代碼

拆分 Horizon worker,避免慢任务堵住支付对账。

把 Redis retry_after 提高到 150 秒,使其大于最长的 worker 超时。

Co-authored-by: Cursor <cursoragent@cursor.com>
chengwl 3 天之前
父節點
當前提交
c155dc17df
共有 2 個文件被更改,包括 67 次插入 和 16 次删除
  1. 66 15
      config/horizon.php
  2. 1 1
      config/queue.php

+ 66 - 15
config/horizon.php

@@ -97,6 +97,10 @@ return [
     */
 
     'waits' => [
+        'redis:payment-reconcile' => 30,
+        'redis:notifications' => 60,
+        'redis:broadcastable' => 60,
+        'redis:api-logs' => 120,
         'redis:default' => 60,
     ],
 
@@ -132,7 +136,7 @@ return [
     */
 
     'silenced' => [
-        // App\Jobs\ExampleJob::class,
+        \Webkul\BagistoApi\Jobs\LogApiRequestJob::class,
     ],
 
     'silenced_tags' => [
@@ -190,40 +194,87 @@ return [
     | Queue Worker Configuration
     |--------------------------------------------------------------------------
     |
-    | Here you may define the queue worker settings used by your application
-    | in all environments. These supervisors and settings handle all your
-    | queued jobs and will be provisioned by Horizon during deployment.
+    | Supervisors are split so a slow index or image conversion on `default`
+    | cannot block payment reconciliation or outbound alerts. Horizon's
+    | supervisor `tries` and `timeout` override the same properties on a job.
+    |
+    | `timeout` must stay below the Redis connection `retry_after`
+    | (config/queue.php, REDIS_QUEUE_RETRY_AFTER). The longest timeout here
+    | is 120 seconds, so retry_after is 150.
+    |
+    | APP_ENV must be `production` or `local`. Any other value falls back to
+    | `defaults` (one process per supervisor).
     |
     */
 
     'defaults' => [
-        'supervisor-1' => [
+        'payments' => [
             'connection' => 'redis',
-            'queue' => ['default'],
-            'balance' => 'auto',
-            'autoScalingStrategy' => 'time',
+            'queue' => ['payment-reconcile'],
+            'balance' => 'simple',
             'maxProcesses' => 1,
             'maxTime' => 0,
             'maxJobs' => 0,
             'memory' => 128,
-            'tries' => 1,
+            'tries' => 3,
             'timeout' => 60,
+            'sleep' => 1,
+            'nice' => 0,
+        ],
+
+        'signals' => [
+            'connection' => 'redis',
+            'queue' => ['notifications', 'broadcastable', 'api-logs'],
+            'balance' => 'simple',
+            'maxProcesses' => 1,
+            'maxTime' => 0,
+            'maxJobs' => 0,
+            'memory' => 128,
+            'tries' => 3,
+            'timeout' => 30,
+            'nice' => 0,
+        ],
+
+        'default' => [
+            'connection' => 'redis',
+            'queue' => ['default'],
+            'balance' => 'auto',
+            'autoScalingStrategy' => 'time',
+            'maxProcesses' => 1,
+            'balanceMaxShift' => 1,
+            'balanceCooldown' => 3,
+            'maxTime' => 0,
+            'maxJobs' => 500,
+            'memory' => 256,
+            'tries' => 3,
+            'timeout' => 120,
             'nice' => 0,
         ],
     ],
 
     'environments' => [
         'production' => [
-            'supervisor-1' => [
-                'maxProcesses' => 10,
-                'balanceMaxShift' => 1,
-                'balanceCooldown' => 3,
+            'payments' => [
+                'maxProcesses' => 2,
+            ],
+            'signals' => [
+                'maxProcesses' => 2,
+            ],
+            'default' => [
+                'minProcesses' => 1,
+                'maxProcesses' => 6,
             ],
         ],
 
         'local' => [
-            'supervisor-1' => [
-                'maxProcesses' => 3,
+            'payments' => [
+                'maxProcesses' => 1,
+            ],
+            'signals' => [
+                'maxProcesses' => 1,
+            ],
+            'default' => [
+                'maxProcesses' => 2,
             ],
         ],
     ],

+ 1 - 1
config/queue.php

@@ -67,7 +67,7 @@ return [
             'driver'       => 'redis',
             'connection'   => env('REDIS_QUEUE_CONNECTION', 'default'),
             'queue'        => env('REDIS_QUEUE', 'default'),
-            'retry_after'  => (int) env('REDIS_QUEUE_RETRY_AFTER', 90),
+            'retry_after'  => (int) env('REDIS_QUEUE_RETRY_AFTER', 150),
             'block_for'    => null,
             'after_commit' => false,
         ],