Kernel.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Console;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
  5. use Illuminate\Support\Facades\Log;
  6. class Kernel extends ConsoleKernel
  7. {
  8. /**
  9. * The Artisan commands provided by your application.
  10. *
  11. * @var array
  12. */
  13. protected $commands = [
  14. //
  15. ];
  16. /**
  17. * Define the application's command schedule.
  18. *
  19. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  20. * @return void
  21. */
  22. protected function schedule(Schedule $schedule)
  23. {
  24. // 每五分钟同步一次 外部定时任务 然后 物料第一次同步检验手动同步
  25. $schedule->command('command:u8_settle_inventory')
  26. ->everyMinute()
  27. ->withoutOverlapping(10) // 锁长时间一点,给第一次同步留足时间
  28. ->onSuccess(function () {
  29. // 2. 只有当 U8SettleInventory 的 handle() 返回 0 时,才执行单据同步
  30. \Illuminate\Support\Facades\Artisan::call('command:u8_settle');
  31. })
  32. ->onFailure(function(){
  33. Log::channel('u8_daily')->warning('物料同步失败,单据同步已挂起。');
  34. });
  35. if (str_contains(PHP_OS, 'WIN')) {
  36. $schedule->call(function () {
  37. // 启动新队列
  38. // 使用 start /B 配合 php 运行,WindowStyle Hidden 隐藏窗口
  39. $cmd = "start /B php artisan queue:work redis --queue=sync_wms_order";
  40. pclose(popen($cmd, "r"));
  41. \Illuminate\Support\Facades\Log::channel('u8_daily')->info("单进程守卫:未检测到运行中的队列,已成功拉起新进程。");
  42. })->everyMinute();
  43. }
  44. }
  45. /**
  46. * Register the commands for the application.
  47. *
  48. * @return void
  49. */
  50. protected function commands()
  51. {
  52. $this->load(__DIR__.'/Commands');
  53. require base_path('routes/console.php');
  54. }
  55. }