| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Console;
- use Illuminate\Console\Scheduling\Schedule;
- use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
- use Illuminate\Support\Facades\Log;
- class Kernel extends ConsoleKernel
- {
- /**
- * The Artisan commands provided by your application.
- *
- * @var array
- */
- protected $commands = [
- //
- ];
- /**
- * Define the application's command schedule.
- *
- * @param \Illuminate\Console\Scheduling\Schedule $schedule
- * @return void
- */
- protected function schedule(Schedule $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->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');
- }
- }
|