| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace UCore\Providers;
- use Illuminate\Support\ServiceProvider;
- use Illuminate\Support\Facades\Schedule;
- class CommandServiceProvider extends ServiceProvider
- {
- public function boot()
- {
- // 注册UCore命令
- $this->commands([
- \UCore\Commands\GenerateModelAnnotation::class,
- \UCore\Commands\GenerateAppTreeCommand::class,
- \UCore\Commands\CleanSizeRotatingLogsCommand::class,
- \UCore\Commands\ExampleCommand::class
- ]);
- // 注册UCore定时任务
- $this->registerSchedules();
- }
- public function register()
- {
- //
- }
- /**
- * 注册UCore相关的定时任务
- *
- * 将原本在 routes/console.php 中的UCore调度配置迁移到此处
- */
- protected function registerSchedules(): void
- {
- // 在应用完全启动后注册定时任务
- $this->app->booted(function () {
- // 每天凌晨3点清理 size_rotating_daily 日志文件(保留配置的天数)
- Schedule::command('ucore:clean-size-rotating-logs')
- ->dailyAt('03:00')
- ->description('清理UCore轮转日志文件');
- });
- }
- }
|