cqp 1 hari lalu
induk
melakukan
2c7c5fdff2
1 mengubah file dengan 44 tambahan dan 0 penghapusan
  1. 44 0
      app/Console/Kernel.php

+ 44 - 0
app/Console/Kernel.php

@@ -25,6 +25,17 @@ class Kernel extends ConsoleKernel
      */
     protected function schedule(Schedule $schedule)
     {
+        // 获取环境模式,默认为 'test'
+        $appMode = env('MY_APP_MODE', 'test');
+
+        if ($appMode === 'production') {
+            $this->production($schedule);
+        }else{
+            $this->test($schedule);
+        }
+    }
+
+    public function production($schedule){
         //开启队列
         if (str_contains(PHP_OS, 'WIN')) {
             $schedule->call(function () {
@@ -63,6 +74,39 @@ class Kernel extends ConsoleKernel
             });
     }
 
+    public function test($schedule){
+        //开启队列
+        if (str_contains(PHP_OS, 'WIN')) {
+            $schedule->call(function () {
+                $queueName = "sync_wms_order";
+                $phpPath = "D:/phpstudy_pro/Extensions/php/php7.4.3nts/php.exe";
+                $artisan = base_path('artisan');
+
+                // 修改点:增加一个 AND 过滤,排除掉包含 "schedule:run" 的进程
+                // 并且确保匹配的是 "queue:work"
+                $checkCmd = 'wmic process where "name=\'php.exe\' and commandline like \'%queue:work%--queue=' . $queueName . '%\' and not commandline like \'%schedule:run%\'" get processid /format:list';
+
+                $output = shell_exec($checkCmd);
+
+                if (empty(trim($output)) || str_contains($output, 'No Instance')) {
+                    // 使用绝对路径启动
+                    $runCmd = "start /B \"\" \"$phpPath\" \"$artisan\" queue:work redis --queue=$queueName --memory=512";
+                    pclose(popen($runCmd, "r"));
+
+                    Log::channel('queue_daily')->info("单进程守卫:未检测到队列[$queueName],已尝试拉起。");
+                } else {
+                    Log::channel('queue_daily')->info('单进程守卫:队列正在运行中,无需拉起。', ['pid' => trim($output)]);
+                }
+            })->everyMinute();
+        }
+
+        $schedule->call(function () {
+            Log::channel('u8_daily')->info('测试环境:正在跳过物料同步,直接执行单据同步...');
+            // 直接调用单据同步命令
+            \Illuminate\Support\Facades\Artisan::call('command:u8_settle');
+        })->everyMinute();
+    }
+
     /**
      * Register the commands for the application.
      *