PHPackages                             macropage/laravel-scheduler-watcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. macropage/laravel-scheduler-watcher

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

macropage/laravel-scheduler-watcher
===================================

logs artisan commands run via scheduler to mysql with plenty of infos, prevent running command again in case of error, allows full monitoing of artisan commands

v3.0(1y ago)9335—0%4MITPHPPHP ^8.1 || ^8.2 || ^8.3

Since Jun 17Pushed 1y ago3 watchersCompare

[ Source](https://github.com/michabbb/laravel-scheduler-watcher)[ Packagist](https://packagist.org/packages/macropage/laravel-scheduler-watcher)[ Docs](https://github.com/macropage/laravel-scheduler-watcher)[ RSS](/packages/macropage-laravel-scheduler-watcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (7)Used By (0)

[![](https://camo.githubusercontent.com/23ac1c781de21fbdf733355ea73b435bc8966743f485730bcb7e7d28fdde8f44/68747470733a2f2f692e696d6775722e636f6d2f364b35334b45322e706e67)](https://camo.githubusercontent.com/23ac1c781de21fbdf733355ea73b435bc8966743f485730bcb7e7d28fdde8f44/68747470733a2f2f692e696d6775722e636f6d2f364b35334b45322e706e67)

Monitor your laravel crons like a pro
=====================================

[](#monitor-your-laravel-crons-like-a-pro)

Log your scheduled commands with start, end, duration, exitcode and output in a seperate database.
Share a custom Mutex between Scheduler and Artisan-Command to identify each call with all parameters and options.

**This package is made for php 8.x and Laravel 9**
If you are working with something older, feel free to fork this project.

Why?
----

[](#why)

Because you should!
Laravel offers some nice [hooks](https://laravel.com/docs/7.x/scheduling#task-hooks) like onFailure but I am totally missing a solution to catch
all important informations of the job-execution itself, like start, stop, duration and exitcode.
My personal goal is to monitor jobs with the following criteria:

- notify me if a job did not run in the last X days/hours/minutes
- notify me if a job ended with exitcode&gt;0
- notify me if a jobs duration takes much longer as it should
- monitor something from a central point even in distributed environments
- monitor individual jobs with my good old nagios (yeah, don´t blame me)
- confirm failed jobs via web `/scheduler-watcher`

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require macropage/laravel-scheduler-watcher
```

Publish config &amp; migration using `php artisan vendor:publish --provider="macropage\LaravelSchedulerWatcher\LaravelSchedulerWatcherServiceProvider"`
Set `mysql_connection` in: `app/config/scheduler-watcher.php`
In case you want a specific table prefix, because you already have a table named "jobs", [you can add one in the config](https://github.com/michabbb/laravel-scheduler-watcher/blob/master/config/scheduler-watcher.php#L8).
Create mysql tables: `php artisan migrate`

Usage
-----

[](#usage)

Write your cron-jobs as usal, but use the "description" to control your logging:

- log
- nooutput
- force

**Example 1:**

```
$schedule->command('dummy:test blabla -c')->everyMinute()->description('Call dummy test');
```

Nothing happens, no logging, laravel default... (i hope so)

**Example 2:**

```
$schedule->command('dummy:test blabla -c')->everyMinute()->description('Call dummy test [log]');
```

Command gets logged into DB, but doesn´t run again, if last exitcode&gt;0

**Example 3:**

```
$schedule->command('dummy:test blabla -c')->everyMinute()->description('Call dummy test [log,nooutput]');
```

Command gets logged, but without output. You can use this to keep the logging-DB small.

**Example 4:**

```
$schedule->command('dummy:test blabla -c')->everyMinute()->description('Call dummy test [log,nooutput,force]');
```

The switch "force" lets run your command, ignoring last exitcode. **be careful: this can spam your DB.**
Personally I would use "force" only with "nooutput".

#### Kernel.php

[](#kernelphp)

To use the logging, you have to include the Trait `LaravelSchedulerWatcher` into your `app\Console\Kernel.php`

```
