<?php
declare(strict_types=1);
namespace App\Providers;
use App\Support\Macros\SchedulingEventMacro;
use Illuminate\Console\Scheduling\Event;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Event::mixin($this->app->make(SchedulingEventMacro::class));
}
}
使用
<?php
declare(strict_types=1);
namespace App\Console;
use App\Console\Commands\CpSyncDataCommand;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
$schedule->command('model:prune', ['--model' => MonitoredScheduledTaskLogItem::class])->daily()->userAppendOutputToMonthly()->withoutOverlapping();
$schedule->command('telescope:prune')->daily()->skip($this->app->isProduction())->userAppendOutputToMonthly()->withoutOverlapping();
$schedule->command(CpSyncDataCommand::class)->hourly()->userAppendOutputToDaily()->withoutOverlapping();
}
}
分享一组比 laravel 调度事件中 AppendOutputTo 方法更为便捷的宏方法
特性
storage/logs/schedules/命令名称/命令名称.log
源码 - app/Support/Macros/SchedulingEventMacro.php
注册
使用
效果 - storage/logs/schedules/cp:sync-data/cp:sync-data-daily-2024-01-16.log
原文链接