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->command('command:u8_settle_inventory') ->everyMinute() ->withoutOverlapping(10) // 锁长时间一点,给第一次同步留足时间 ->onSuccess(function () { // 2. 只有当 U8SettleInventory 的 handle() 返回 0 时,才执行单据同步 \Illuminate\Support\Facades\Artisan::call('command:u8_settle'); }) ->onFailure(function(){ Log::channel('u8_daily')->warning('物料同步失败,单据同步已挂起。'); }); } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__.'/Commands'); require base_path('routes/console.php'); } }