在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):spatie/laravel-schedule-monitor开源软件地址(OpenSource Url):https://github.com/spatie/laravel-schedule-monitor开源编程语言(OpenSource Language):PHP 92.3%开源软件介绍(OpenSource Introduction):Monitor scheduled tasks in a Laravel appThis 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 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 usWe 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. InstallationYou can install the package via composer: composer require spatie/laravel-schedule-monitor If you need Laravel 8 support, you can install v2 of the package using Preparing the databaseYou must publish and run migrations: php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-migrations"
php artisan migrate Publishing the config fileYou can publish the config file with: php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-config" This is the contents of the published config file: 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
* `Spatie\ScheduleMonitor\Models\MonitoredScheduledTask` Model.
*/
'monitored_scheduled_task' => Spatie\ScheduleMonitor\Models\MonitoredScheduledTask::class,
/*
* The model you want to use as a MonitoredScheduledTaskLogItem model needs to extend the
* `Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem` 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,
],
]; Cleaning the databaseThe schedule monitor will log each start, finish and failure of all scheduled jobs. After a while the Use Laravel's model pruning feature , you can delete old // 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();
}
} Syncing the scheduleEvery time you deploy your application, you should execute the schedule-monitor:sync 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 UsageTo monitor your schedule you should first run To view all monitored scheduled tasks, you can run The package will write an entry to the Naming tasksSchedule 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 Here's an example. // 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');
} 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 timeWhen the package detects that the last run of a scheduled task did not run in time, the 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 // in app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('your-command')->daily()->graceTimeInMinutes(10);
} Ignoring scheduled tasksYou can avoid a scheduled task being monitored by tacking on // in app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('your-command')->daily()->doNotMonitor();
} Storing output in the databaseYou can store the output by tacking on // in app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('your-command')->daily()->storeOutputInDb();
} The output will be stored in the MultitenancyIf you're using spatie/laravel-multitenancy you should add the 'not_tenant_aware_jobs' => [
// ...
\Spatie\ScheduleMonitor\Jobs\PingOhDearJob::class,
] Without it, the Getting notified when a scheduled task doesn't finish in timeThis 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. composer require ohdearapp/ohdear-php-sdk Next you, need to make sure the php artisan schedule-monitor:verify To sync your schedule with Oh Dear run this command: php artisan schedule-monitor:sync After that, the 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 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 Here's an example where Oh Dear will send a notification if the task didn't finish by 00:10. // in app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('your-command')->daily()->graceTimeInMinutes(10);
} Unsupported methodsCurrently, this package does not work for tasks that use these methods:
Third party scheduled task monitorsWe 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: Testingcomposer test ChangelogPlease see CHANGELOG for more information on what has changed recently. ContributingPlease see CONTRIBUTING for details. SecurityIf you've found a bug regarding security please mail [email protected] instead of using the issue tracker. CreditsLicenseThe MIT License (MIT). Please see License File for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论