### Install Spatie Laravel Schedule Monitor Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Installs the package using Composer. For Laravel 8 support, version 2 can be installed. ```bash composer require spatie\/laravel-schedule-monitor # For Laravel 8 support: composer require spatie\/laravel-schedule-monitor:^2 ``` -------------------------------- ### Listing Monitored Tasks Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Shows how to use the `schedule-monitor:list` command to view all monitored scheduled tasks. This command provides details on when each task last started, finished, or failed. ```bash php artisan schedule-monitor:list ``` -------------------------------- ### Install Oh Dear PHP SDK Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md This command installs the necessary Oh Dear PHP SDK, which is required for integrating the schedule monitor with Oh Dear's cron check functionality. This integration allows Oh Dear to notify you if a scheduled task does not complete within the expected timeframe. ```bash composer require ohdearapp/ohdear-php-sdk ``` -------------------------------- ### Disable Oh Dear Monitoring for a Task Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md This example demonstrates how to prevent a specific scheduled task from being monitored by Oh Dear, even if the package is configured for Oh Dear integration. The `doNotMonitorAtOhDear` method ensures that Oh Dear will not send notifications for this particular task. ```php // in app/Console/Kernel.php protected function schedule(Schedule $schedule) { $schedule->command('your-command')->daily()->doNotMonitorAtOhDear(); } ``` -------------------------------- ### Prepare Database for Schedule Monitor Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Publishes and runs the necessary migrations to create the database tables for the schedule monitor. ```bash php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-migrations" php artisan migrate ``` -------------------------------- ### Publish Schedule Monitor Configuration Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Publishes the configuration file for the schedule monitor package, allowing customization of settings. ```bash php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-config" ``` -------------------------------- ### Syncing Schedule with Oh Dear Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Explains the `schedule-monitor:sync` Artisan command, which synchronizes your application's schedule with the database and optionally with Oh Dear. It's recommended to run this command during deployment. ```bash php artisan schedule-monitor:sync ``` -------------------------------- ### Run Tests Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md This command executes the test suite for the spatie/laravel-schedule-monitor package. It's recommended to run tests to ensure the package is functioning correctly within your project. ```bash composer test ``` -------------------------------- ### Schedule Monitor Configuration File Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md The default configuration file for the spatie/laravel-schedule-monitor package, detailing options for log retention, date formatting, model configuration, and Oh Dear integration. ```php return [ /* * 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. * Here you can specify the amount of days log items should be kept. * * Use Laravel's pruning command to delete old `MonitoredScheduledTaskLogItem` models. * More info: https://laravel.com/docs/9.x/eloquent#mass-assignment */ 'delete_log_items_older_than_days' => 30, /* * The date format used for all dates displayed on the output of commands * provided by this package. */ 'date_format' => 'Y-m-d H:i:s', 'models' => [ /* * The model you want to use as a MonitoredScheduledTask model needs to extend the * `SpatieScheduleMonitorModelsMonitoredScheduledTask` Model. */ 'monitored_scheduled_task' => Spatie\ScheduleMonitor\Models\MonitoredScheduledTask::class, /* * The model you want to use as a MonitoredScheduledTaskLogItem model needs to extend the * `SpatieScheduleMonitorModelsMonitoredScheduledTaskLogItem` Model. */ 'monitored_scheduled_log_item' => Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem::class, ], /* * Oh Dear can notify you via Mail, Slack, SMS, web hooks, ... when a * scheduled task does not run on time. * * More info: https://ohdear.app/cron-checks */ 'oh_dear' => [ /* * You can generate an API token at the Oh Dear user settings screen * * https://ohdear.app/user/api-tokens */ 'api_token' => env('OH_DEAR_API_TOKEN', ''), /* * The id of the site you want to sync the schedule with. * * You'll find this id on the settings page of a site at Oh Dear. */ 'site_id' => env('OH_DEAR_SITE_ID'), /* * To keep scheduled jobs as short as possible, Oh Dear will be pinged * via a queued job. Here you can specify the name of the queue you wish to use. */ 'queue' => env('OH_DEAR_QUEUE'), /* * `PingOhDearJob`s will automatically be skipped if they've been queued for * longer than the time configured here. */ 'retry_job_for_minutes' => 10, ], ]; ``` -------------------------------- ### Verify Schedule Monitor Configuration Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md This Artisan command verifies that the `api_token` and `site_id` for the schedule monitor are correctly configured in your application's settings. These values are essential for the package to communicate with the Oh Dear service. ```bash php artisan schedule-monitor:verify ``` -------------------------------- ### Multitenancy Configuration for PingOhDearJob Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md For applications using spatie/laravel-multitenancy, it's necessary to register the `PingOhDearJob` in the `not_tenant_aware_jobs` array within the `config/multitenancy.php` file. This prevents the job from failing due to the absence of a tenant context when it runs. ```php 'not_tenant_aware_jobs' => [ // ... \Spatie\ScheduleMonitor\Jobs\PingOhDearJob::class, ] ``` -------------------------------- ### Sync Scheduled Tasks with Oh Dear Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md This command synchronizes your application's scheduled tasks with the Oh Dear service. After running this, the `list` command should reflect that all your scheduled tasks are registered with Oh Dear, enabling Oh Dear to monitor their execution. ```bash php artisan schedule-monitor:sync ``` -------------------------------- ### Non-Destructive Sync Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Illustrates how to use the `--keep-old` flag with the `schedule-monitor:sync` command for non-destructive synchronization with Oh Dear. This method pushes only new tasks without removing existing ones. ```bash php artisan schedule-monitor:sync --keep-old ``` -------------------------------- ### Manually Naming Scheduled Tasks Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Demonstrates how to manually assign a name to a scheduled task using the `monitorName()` method. This is useful for tasks like scheduled closures where a name cannot be automatically determined. ```php // in app/Console/Kernel.php protected function schedule(Schedule $schedule) { $schedule->command('your-command')->daily()->monitorName('a-custom-name'); $schedule->call(fn () => 1 + 1)->hourly()->monitorName('addition-closure'); } ``` -------------------------------- ### Store Scheduled Task Output in Database Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md This snippet demonstrates how to configure a Laravel scheduled command to store its output directly into the database. The output is saved in the 'output' key within the 'meta' column of the 'monitored_scheduled_task_log_items' table. This requires the `storeOutputInDb` method to be chained to the schedule definition. ```php // in app/Console/Kernel.php protected function schedule(Schedule $schedule) { $schedule->command('your-command')->daily()->storeOutputInDb(); } ``` -------------------------------- ### Customizing Grace Time Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Explains how to customize the grace time for scheduled tasks using the `graceTimeInMinutes()` method. This grace time determines how long a task has to finish before being flagged as late. ```php // in app/Console/Kernel.php protected function schedule(Schedule $schedule) { $schedule->command('your-command')->daily()->graceTimeInMinutes(10); } ``` -------------------------------- ### Pruning Old Log Items Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Demonstrates how to use Laravel's model pruning feature to automatically delete old `MonitoredScheduledTaskLogItem` models. This helps manage database size by removing logs older than a configured number of days. ```php // app/Console/Kernel.php use Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem; class Kernel extends ConsoleKernel { protected function schedule(Schedule $schedule) { $schedule->command('model:prune', ['--model' => MonitoredScheduledTaskLogItem::class])->daily(); } } ``` -------------------------------- ### Customize Oh Dear Grace Time Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md This snippet shows how to set a custom grace time for Oh Dear monitoring of a specific scheduled task. The `graceTimeInMinutes` method allows you to define how many minutes Oh Dear should wait for a task to complete before sending a notification. By default, this grace time is 5 minutes. ```php // in app/Console/Kernel.php protected function schedule(Schedule $schedule) { $schedule->command('your-command')->daily()->graceTimeInMinutes(10); } ``` -------------------------------- ### Ignoring Scheduled Tasks Source: https://github.com/spatie/laravel-schedule-monitor/blob/main/README.md Shows how to prevent a scheduled task from being monitored by using the `doNotMonitor()` method. This is useful for tasks that you do not want to track with the schedule monitor. ```php // in app/Console/Kernel.php protected function schedule(Schedule $schedule) { $schedule->command('your-command')->daily()->doNotMonitor(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.