mirzabusatlic/laravel-schedule-monitor

此包的最新版本(v1.02)没有可用的许可证信息。

监控数据库表中计划任务的输出

v1.02 2017-07-11 14:00 UTC

This package is auto-updated.

Last update: 2024-09-17 10:09:09 UTC


README

跟踪您的计划任务输出到数据库表中。

安装

  1. 通过composer安装:composer require mirzabusatlic/laravel-schedule-monitor
  2. Busatlic\ScheduleMonitor\ScheduleMonitorServiceProvider::class 添加到您的 config/app.php 中的 $providers 列表中。
  3. 使用 php artisan vendor:publish --provider=Busatlic\\ScheduleMonitor\\ScheduleMonitorServiceProvider 发布迁移。
  4. 运行 php artisan migrate 在您的数据库中创建 scheduled_events 表。

使用方法

  • 在您的 app/Console/Kernel.php 中包含 Busatlic\ScheduleMonitor\MonitorsSchedule 特性。
  • 在您在 schedule() 中定义了计划命令之后调用 $this->monitor($schedule)

这看起来可能像这样

<?php

namespace App\Console;

use Busatlic\ScheduleMonitor\MonitorsSchedule;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    use MonitorsSchedule;

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Console\Commands\DeleteFilesCommand::class,
        \App\Console\Commands\FlushEventsCommand::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule $schedule
     *
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('files:delete')->dailyAt('00:05');
        
        $schedule->command('events:flush')->hourly();

        $this->monitor($schedule);
    }
}

每次运行计划命令时,其输出将被插入到 scheduled_events 表中。