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