|
|
@@ -3,6 +3,39 @@
|
|
|
use Illuminate\Foundation\Inspiring;
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
|
|
+use Illuminate\Support\Facades\Schedule;
|
|
|
+
|
|
|
+use App\Jobs\DailyReportJob;
|
|
|
+
|
|
|
Artisan::command('inspire', function () {
|
|
|
$this->comment(Inspiring::quote());
|
|
|
})->purpose('Display an inspiring quote');
|
|
|
+
|
|
|
+
|
|
|
+// // 这里定义你的定时任务(和以前 Kernel.php 里的 schedule 方法内容一样)
|
|
|
+// Schedule::command('inspire')->hourly();
|
|
|
+
|
|
|
+// // 每天运行一次的例子(凌晨1点)
|
|
|
+// Schedule::command('your:command-name')
|
|
|
+// ->dailyAt('01:00')
|
|
|
+// ->timezone('Asia/Shanghai')
|
|
|
+// ->onOneServer()
|
|
|
+// ->runInBackground();
|
|
|
+
|
|
|
+// // 或者调用闭包
|
|
|
+// Schedule::call(function () {
|
|
|
+// // 你的业务代码...
|
|
|
+// \Log::info('每日任务执行了 ' . now());
|
|
|
+// })->daily()->name('每日清理任务')->withoutOverlapping();
|
|
|
+
|
|
|
+// // 或者调度一个 Job 类
|
|
|
+// Schedule::job(new \App\Jobs\ProcessReports)->dailyAt('03:00');
|
|
|
+
|
|
|
+// 每天凌晨 2:00 自动 dispatch 这个 Job
|
|
|
+Schedule::job(new DailyReportJob)
|
|
|
+ ->dailyAt('02:00')
|
|
|
+ ->timezone('Asia/Shanghai') // 根据你的服务器时区调整
|
|
|
+ ->onOneServer() // 多服务器部署时防止重复执行(推荐)
|
|
|
+ ->withoutOverlapping() // 防止重叠执行(如果上一次还没完,这次不跑)
|
|
|
+ ->name('daily-report-job') // 给任务起个名字,便于日志追踪
|
|
|
+ ->description('每天生成日报表');
|