Download the PHP package spatie/laravel-schedule-monitor without Composer

On this page you can find all versions of the php package spatie/laravel-schedule-monitor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-schedule-monitor

Monitor scheduled tasks in a Laravel app

Latest Version on Packagist Total Downloads

This package will monitor your Laravel schedule. It will write an entry to a log table in the db each time a schedule tasks starts, end, fails or is skipped. Using the list command you can check when the scheduled tasks have been executed.

screenshot

This package can also sync your schedule with Oh Dear. Oh Dear will send you a notification whenever a scheduled task doesn't run on time or fails.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

If you need Laravel 8 support, you can install v2 of the package using composer require spatie/laravel-schedule-monitor:^2.

Preparing the database

You must publish and run migrations:

Publishing the config file

You can publish the config file with:

This is the contents of the published config file:

Cleaning the database

The schedule monitor will log each start, finish and failure of all scheduled jobs. After a while the monitored_scheduled_task_log_items might become big.

Use Laravel's model pruning feature , you can delete old MonitoredScheduledTaskLogItem models. Models older than the amount of days configured in the delete_log_items_older_than_days in the schedule-monitor config file, will be deleted.

Syncing the schedule

Every time you deploy your application, you should execute the schedule-monitor:sync command

This command is responsible for syncing your schedule with the database, and optionally Oh Dear. We highly recommend adding this command to the script that deploys your production environment.

In a non-production environment you should manually run schedule-monitor:sync. You can verify if everything synced correctly using schedule-monitor:list.

Note: Running the sync command will remove any other cron monitors that you've defined other than the application schedule.

If you would like to use non-destructive syncs to Oh Dear so that you can monitor other cron tasks outside of Laravel, you can use the --keep-old flag. This will only push new tasks to Oh Dear, rather than a full sync. Note that this will not remove any tasks from Oh Dear that are no longer in your schedule.

Usage

To monitor your schedule you should first run schedule-monitor:sync. This command will take a look at your schedule and create an entry for each task in the monitored_scheduled_tasks table.

screenshot

To view all monitored scheduled tasks, you can run schedule-monitor:list. This command will list all monitored scheduled tasks. It will show you when a scheduled task has last started, finished, or failed.

screenshot

The package will write an entry to the monitored_scheduled_task_log_items table in the db each time a schedule tasks starts, end, fails or is skipped. Take a look at the contest of that table if you want to know when and how scheduled tasks did execute. The log items also hold other interesting metrics like memory usage, execution time, and more.

Naming tasks

Schedule monitor will try to automatically determine a name for a scheduled task. For commands this is the command name, for anonymous jobs the class name of the first argument will be used. For some tasks, like scheduled closures, a name cannot be determined automatically.

To manually set a name of the scheduled task, you can tack on monitorName().

Here's an example.

When you change the name of task, the schedule monitor will remove all log items of the monitor with the old name, and create a new monitor using the new name of the task.

Setting a grace time

When the package detects that the last run of a scheduled task did not run in time, the schedule-monitor list will display that task using a red background color. In this screenshot the task named your-command ran too late.

screenshot

The package will determine that a task ran too late if it was not finished at the time it was supposed to run + the grace time. You can think of the grace time as the number of minutes that a task under normal circumstances needs to finish. By default, the package grants a grace time of 5 minutes to each task.

You can customize the grace time by using the graceTimeInMinutes method on a task. In this example a grace time of 10 minutes is used for the your-command task.

Ignoring scheduled tasks

You can avoid a scheduled task being monitored by tacking on doNotMonitor when scheduling the task.

Storing output in the database

You can store the output by tacking on storeOutputInDb when scheduling the task.

The output will be stored in the monitored_scheduled_task_log_items table, in the output key of the meta column.

Multitenancy

If you're using spatie/laravel-multitenancy you should add the PingOhDearJob to the not_tenant_aware_jobs array in config/multitenancy.php.

Without it, the PingOhDearJob will fail as no tenant will be set.

Getting notified when a scheduled task doesn't finish in time

This package can sync your schedule with the Oh Dear cron check. Oh Dear will send you a notification whenever a scheduled task does not finish on time.

To get started you will first need to install the Oh Dear SDK.

Next you, need to make sure the api_token and site_id keys of the schedule-monitor are filled with an API token, and an Oh Dear site id. To verify that these values hold correct values you can run this command.

screenshot

To sync your schedule with Oh Dear run this command:

screenshot

After that, the list command should show that all the scheduled tasks in your app are registered on Oh Dear.

screenshot

To keep scheduled jobs as short as possible, Oh Dear will be pinged via queued jobs. To ensure speedy delivery to Oh Dear, and to avoid false positive notifications, we highly recommend creating a dedicated queue for these jobs. You can put the name of that queue in the queue key of the config file.

Oh Dear will wait for the completion of a schedule tasks for a given amount of minutes. This is called the grace time. By default, all scheduled tasks will have a grace time of 5 minutes. To customize this value, you can tack on graceTimeInMinutes to your scheduled tasks.

Here's an example where Oh Dear will send a notification if the task didn't finish by 00:10.

Disabling Oh Dear for individual tasks

If you want to have a task monitored by the schedule monitor, but not by Oh Dear, you can tack on doMonitorAtOhDear to your scheduled tasks.

Unsupported methods

Currently, this package does not work for tasks that use these methods:

Third party scheduled task monitors

We assume that, when your scheduled tasks do not run properly, a scheduled task that sends out notifications would probably not run either. That's why this package doesn't send out notifications by itself.

These services can notify you when scheduled tasks do not run properly:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-schedule-monitor with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/bus Version ^9.0|^10.0|^11.0
lorisleiva/cron-translator Version ^0.3.0|^0.4.0
nesbot/carbon Version ^2.63|^3.0
nunomaduro/termwind Version ^1.10.1|^2.0
spatie/laravel-package-tools Version ^1.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package spatie/laravel-schedule-monitor contains the following files

Loading the files please wait ....