定制 cronpulse/laravel-monitor 二次开发

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

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

cronpulse/laravel-monitor

最新稳定版本:v1.0.0

Composer 安装命令:

composer require cronpulse/laravel-monitor

包简介

A cronjob monitoring library for Laravel using Cronpulse.live

README 文档

README

Cronpulse Laravel Monitor is a monitoring library for Laravel applications that allows you to easily send heartbeat pings, start/stop job pings, and wrap jobs for monitoring. This helps ensure your scheduled tasks are running as expected and provides insights into job failures or successes.

Installation

To install the package, add it to your Laravel project's composer.json and run composer update:

composer require cronpulse/laravel-monitor

Configuration

After installation, publish the configuration file:

php artisan vendor:publish --provider="Cronpulse\\LaravelMonitor\\MonitorServiceProvider"

Add your job key to your .env file:

MONITOR_JOB_KEY=your-real-job-key

This job key is essential for authenticating your pings with cronpulse.

Usage

Basic Monitoring

You can manually ping cronpulse by using the Monitor class. This can be useful for sending status updates about your scheduled jobs.

Starting a Job

To start monitoring a job:

use Cronpulse\LaravelMonitor\Monitor;

$monitor = new Monitor();
$monitor->ping('start');

Marking a Job as Successful

After your job completes successfully:

$monitor->ping('success');

Marking a Job as Failed

If your job encounters an error and fails:

$dynamicError = 'This is a dynamic error message';
$monitor->ping(['state' => 'fail', 'message' => $dynamicError]);

Sending Heartbeat Pings

You can also send heartbeat pings to monitor the regular execution of a task:

$monitor->ping('beat');

Wrapping a Job

The wrap function provides a convenient way to monitor a job's start and completion, including error handling.

Example with a Successful Job

To wrap a job function that should complete successfully:

use function Cronpulse\LaravelMonitor\wrap;

wrap('your-job-key', function() {
    // Your job logic here
    return true;
});

Example with a Failing Job

To wrap a job function that might fail:

wrap('your-job-key', function() {
    // Simulate job failure
    throw new \Exception('Something went wrong');
});

The wrap function will automatically handle sending pings for the job start, success, or failure.

Testing

The library includes tests to ensure its functionality. You can run the tests using Laravel’s test runner:

php artisan test

Ensure that your .env file contains the correct MONITOR_JOB_KEY for the tests to run against your monitoring service.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-08-10