CommandServiceProvider.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace UCore\Providers;
  3. use Illuminate\Support\ServiceProvider;
  4. use Illuminate\Support\Facades\Schedule;
  5. class CommandServiceProvider extends ServiceProvider
  6. {
  7. public function boot()
  8. {
  9. // 注册UCore命令
  10. $this->commands([
  11. \UCore\Commands\GenerateModelAnnotation::class,
  12. \UCore\Commands\GenerateAppTreeCommand::class,
  13. \UCore\Commands\CleanSizeRotatingLogsCommand::class,
  14. \UCore\Commands\ExampleCommand::class
  15. ]);
  16. // 注册UCore定时任务
  17. $this->registerSchedules();
  18. }
  19. public function register()
  20. {
  21. //
  22. }
  23. /**
  24. * 注册UCore相关的定时任务
  25. *
  26. * 将原本在 routes/console.php 中的UCore调度配置迁移到此处
  27. */
  28. protected function registerSchedules(): void
  29. {
  30. // 在应用完全启动后注册定时任务
  31. $this->app->booted(function () {
  32. // 每天凌晨3点清理 size_rotating_daily 日志文件(保留配置的天数)
  33. Schedule::command('ucore:clean-size-rotating-logs')
  34. ->dailyAt('03:00')
  35. ->description('清理UCore轮转日志文件');
  36. });
  37. }
  38. }