Monitor Scheduled Tasks in Laravel

If you have tasks that run using Laravel’s Task Scheduling feature, you may want to monitor that these tasks ran and what output they generated.

You can currently use sendOutputTo() to log the output to a file, or emailOutputTo to email yourself the output, but what if you want to track the output in another repository, such as a database table?

I wrote a very simple package that will track your scheduled tasks in a database table. Visit the Github repository to see the code and instructions on how to install the package.

 

Console/Kernel.php

To see how to use this package, take a look at the 3 highlighted lines below.

<?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);
    }
}

 

I will take a look at updating this package to take advantage of notifications that will be available in the release of Laravel 5.3.

Laravel Schedule Monitor Github Repository

One thought on “Monitor Scheduled Tasks in Laravel

  1. srikanth Reply

    Hi,

    can you please me tell me how to modify/customize the output generated by scheduler. I do not want such as 32m and 39M etc in my file.

    Regards,
    Srikanth

Leave a Reply

Your email address will not be published. Required fields are marked *