| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?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)
- {
- // 每五分钟同步一次 外部定时任务 然后 物料第一次同步检验手动同步
- $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('物料同步失败,单据同步已挂起。');
- });
- if (str_contains(PHP_OS, 'WIN')) {
- $schedule->call(function () {
- // 启动新队列
- // 使用 start /B 配合 php 运行,WindowStyle Hidden 隐藏窗口
- $cmd = "start /B php artisan queue:work redis --queue=sync_wms_order";
- pclose(popen($cmd, "r"));
- \Illuminate\Support\Facades\Log::channel('u8_daily')->info("单进程守卫:未检测到运行中的队列,已成功拉起新进程。");
- })->everyMinute();
- }
- }
- /**
- * Register the commands for the application.
- *
- * @return void
- */
- protected function commands()
- {
- $this->load(__DIR__.'/Commands');
- require base_path('routes/console.php');
- }
- }
|