承接 norbybaru/easypeasy-runner 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

norbybaru/easypeasy-runner

最新稳定版本:v0.3.2

Composer 安装命令:

composer require norbybaru/easypeasy-runner

包简介

background jobs, independent of Laravel's built-in queue system

关键字:

README 文档

README

Run Unit Tests Check & fix Code styling

Background Job Runner

A tailored custom system to execute PHP classes as background jobs, independent of Laravel's built-in queue system.

Feature

  • Priority queue
  • Retry attempt
  • Delay process
  • Retry failed jobs

Installation

composer require norbybaru/easypeasy-runner

Publish configuration

php artisan vendor:publish --tag="easypeasy-runner-config"

Publish migration

php artisan vendor:publish --tag="easypeasy-runner-migration"

Run migration

php artisan migrate

Usage

Configure Whitelist class namespaces

To prevent execution of unauthorized classes, you should update config/easypeasy-runner.php file with allowed class namespace or fully qualified class name.

eg.

<?php

return [
    ....
    'allowed_namespaces' => [
        'App\\Services\\'
    ],
    ...
]

Start background process

Run the following artisan command to start processing background job

php artisan background:jobs:process

Basic

<?php

use App\Services\EmailService;
use function NorbyBaru\EasyRunner\runBackgroundJob;

runBackgroundJob(
    className: EmailService::class, 
    methodName: 'sendNotification',
    params: [
        'user@example.com', 
        'Welcome',
        'This is welcome message'
    ]
);

PS. Ensure to set params value in correct orders as in function definition eg.

<?php

class EmailService
{
    public function sendNotification(string $email, string $subject, string $message)
    {
        // Execute
    }
}

Advanced

Configure priority job

Available options: low, medium, high

<?php

use function NorbyBaru\EasyRunner\runBackgroundJob;

runBackgroundJob(
    className: EmailService::class,
    methodName: 'sendUrgentNotification',
    params: [
        'user@example.com',
        'Emergency Alert'
    ],
    options: [
        'priority' => 'high'
    ]
);

Configure delay (seconds) job

<?php

use function NorbyBaru\EasyRunner\runBackgroundJob;

runBackgroundJob(
    className: EmailService::class,
    methodName: 'sendUrgentNotification',
    params: [
        'user@example.com',
        'Emergency Alert'
    ],
    options: [
        'priority' => 'low',
        'delay' => 120
    ]
);

Override Retry configuration

<?php
use App\Services\ReportGenerator;
use function NorbyBaru\EasyRunner\runBackgroundJob;

runBackgroundJob(
    className: ReportGenerator::class, 
    methodName: 'generateMonthlyReport', 
    params: [
        '2023-11'
    ], 
    options: [
        'retry_attempts' => 5
    ]
);

Monitoring

View info logs

New file are generated daily with date format background_jobs-YYY-MM-DD. eg. background_jobs-2024-11-23.log.

tail -f background_jobs-2024-11-23.log

View Error logs

New file are generated daily with date format background_jobs_errors-YYY-MM-DD. eg. background_jobs_errors-2024-11-23.log.

tail -f background_jobs_errors-2024-11-23.log

Cleanup Jobs table

php artisan background:jobs:cleanup

Jobs Stats

Display Background Jobs Stats

php artisan background:jobs:stats

Live update of Background Jobs Stats

php artisan background:jobs:stats --live

Display only failed Jobs

php artisan background:jobs:stats --failed

Retry Failed Jobs

Retry all failed jobs

php artisan background:jobs:retry-failed

Retry a single failed job

php artisan background:jobs:retry-failed --id={jobID}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-23