定制 smitmartijn/laravel-schedule-monitor 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

smitmartijn/laravel-schedule-monitor

Composer 安装命令:

composer require smitmartijn/laravel-schedule-monitor

包简介

Monitor Laravel scheduled jobs with heartbeats

README 文档

README

Monitor your Laravel scheduled tasks with automatic heartbeats and receive alerts when jobs fail to run.

Disclaimer: I built this for WhatPulse, and don't intend on productizing it beyond my use cases. PRs are welcome, though!

Installation

You can install the package via composer:

composer require smitmartijn/laravel-schedule-monitor

After installing the package, publish the configuration file:

php artisan vendor:publish --provider="Smitmartijn\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="config"

Configuration

After publishing the configuration file, you'll find it at config/schedule-monitor.php. You'll need to set these environment variables in your .env file:

SCHEDULE_MONITOR_API_URL=https://your-monitor-app.pages.dev
SCHEDULE_MONITOR_API_TOKEN=your-api-token

Make sure the API token matches the one you set in your monitoring application.

Usage

Syncing Your Scheduled Tasks

Before the monitoring can begin, you need to sync your scheduled tasks with the monitoring application. Run the following command:

php artisan schedule:monitor:sync

This will scan all your scheduled tasks and send them to the monitoring application. It's recommended to run this command in your deployment process so that any changes to your scheduled tasks are automatically synced.

Testing Heartbeats

You can send a test heartbeat for a job to verify the monitoring connection is working properly:

php artisan schedule:monitor:test-heartbeat "php artisan your:command"

This will send a test heartbeat for the specified job. The job name should match exactly what appears in the monitoring app after running the sync command.

Options:

  • --status=success|failure - Set the job status (default: success)
  • --runtime=0.5 - Set a custom runtime in seconds (default: 0.1)

Example:

# Test a job with failure status
php artisan schedule:monitor:test-heartbeat "php artisan emails:send" --status=failure

Customizing Monitoring

By default, all scheduled tasks will be monitored. If you want to exclude specific tasks from monitoring, you can use the withoutMonitoring method in your scheduler:

// In app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
    // This job will be monitored
    $schedule->command('emails:send')->daily();

    // This job will NOT be monitored
    $schedule->command('horizon:snapshot')
        ->everyFiveMinutes()
        ->withoutMonitoring();
}

Setting Custom Grace Periods

You can set a custom grace period for individual tasks using the graceMinutes method:

$schedule->command('import:data')
    ->daily()
    ->graceMinutes(60); // Allow up to 60 minutes delay before marking as missed

If not specified, the default grace period from the configuration will be used.

How It Works

  1. When you run the schedule:monitor:sync command, all eligible scheduled tasks are sent to the monitoring application.
  2. When a task finishes running, the package automatically sends a heartbeat to the monitoring application.
  3. The monitoring application checks if tasks are running on schedule and raises alerts when they miss their expected run time.

Monitoring Multiple Applications

You can use the same monitoring application for multiple Laravel applications. Each application will need its own API token, and its jobs will be tracked separately.

Troubleshooting

Heartbeats Not Being Sent

Make sure:

  1. The Laravel application can reach the monitoring API URL
  2. The API tokens match on both sides
  3. The scheduled task isn't excluded by the ignore patterns in the config

Check Connectivity

You can test the connection to the monitoring service by running:

php artisan schedule:monitor:sync

If this command completes successfully, the connection is working.

Security

If you discover any security issues, please use the issue tracker.

License

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

smitmartijn/laravel-schedule-monitor 适用场景与选型建议

smitmartijn/laravel-schedule-monitor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 smitmartijn/laravel-schedule-monitor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 smitmartijn/laravel-schedule-monitor 我们能提供哪些服务?
定制开发 / 二次开发

基于 smitmartijn/laravel-schedule-monitor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-12