ninoslavjaric/queue-manager
最新稳定版本:v1.1.0
Composer 安装命令:
composer require ninoslavjaric/queue-manager
包简介
A Laravel-based queue management system with background job support.
README 文档
README
Custom Queue Manager for Laravel
Overview
The Custom Queue Manager is a Laravel plugin designed to execute PHP classes as background jobs, independent of Laravel's built-in queue system. This system provides scalability, error handling, and ease of use while executing tasks asynchronously. It supports multiple queue storage drivers, starting with Eloquent and planning to extend to Redis.
Installation
-
Install the package via Composer:
composer require ninoslavjaric/queue-manager
-
Run migrations to set up the necessary database tables:
php artisan migrate
-
Add the scheduler to your crontab to run the queue daemon:
php artisan schedule:run
Configuration
The configuration file for the QueueManager may be overriden and can be found in config/custom_queue.php. Here's an example of the configuration:
return [ 'driver' => env('CUSTOM_QUEUE_DRIVER', 'eloquent'), 'queue-pool-limit' => 2, 'drivers' => [ 'eloquent' => \Nino\CustomQueueLaravel\Services\QueueManager\Eloquent::class, 'redis' => \Nino\CustomQueueLaravel\Services\QueueManager\Redis::class, ], // Optional: Limit queueable classes 'whitelisted_classes' => [], 'blacklisted_classes' => [], 'task-class' => \Nino\CustomQueueLaravel\Models\CustomQueueTask::class ];
driver: Choose the queue storage driver (Eloquent, Redis).queue-pool-limit: Set the maximum number of concurrent tasks that can be processed. Default is 2.drivers: Define the drivers (currently Eloquent and Redis).whitelisted_classes&blacklisted_classes: Use these arrays to restrict which classes are allowed to be queued.
Main Components
QueueManager
The central class in this solution is QueueManager. It orchestrates all the actions in the queue system. It is an abstract class, and different storage backends extend it (e.g., Eloquent, Redis).
Crucial Methods
-
queueDaemonFunction:- This function is scheduled to run every 2 seconds.
- It retrieves idle tasks and creates asynchronous background jobs to execute specific tasks.
-
runBackgroundJob:- This function is executed by an asynchronous background job to process the task.
-
append:- This method pushes a task to the queue table, but only if it passes the validation.
-
push:- Adds a task to the queue table.
-
pop:- Fetches a list of tasks with the highest priority and oldest timestamps. You can specify the number of tasks to retrieve via the
limitparameter.
- Fetches a list of tasks with the highest priority and oldest timestamps. You can specify the number of tasks to retrieve via the
Logging
There are two types of logs:
- Default logger: Logs regular task execution.
- Error logger: Logs failed tasks or errors during task processing.
The log entries are structured as follows:
[2024-11-21 20:36:47] local.INFO: [nino/app/Services/QueueManager.php:219] {"flag":"custom-queue:daemon","queuePoolLimit":3} -----> Cancelling tasks that aren't running in system
- Log format: Includes context (e.g., task details) and the log level.
- Log files:
background_jobs.log: For regular logs.background_jobs_errors.log: For error logs.
Queue Daemon
The queue system runs a daemon that continuously monitors and executes background tasks. The daemon is triggered via the custom-queue:daemon command, and it processes tasks using the php artisan custom-queue:task-bg-execute {uuid} command.
Example Log Entries
- Task preparation:
[2024-11-21 20:36:47] local.INFO: [nino/app/Services/QueueManager.php:233] {"flag":"custom-queue:daemon","queuePoolLimit":3,"tasksExtractedCount":2} -----> Preparing tasks for execution - Task execution:
[2024-11-21 20:36:47] local.INFO: [nino/app/Services/QueueManager.php:246] {"flag":"custom-queue:daemon","queuePoolLimit":3,"tasksExtractedCount":2,"cmd":"'\/usr\/local\/bin\/php' '\/var\/www\/html\/artisan' 'custom-queue:task-bg-execute' '4919f8b9-06b9-4902-a96f-80c9bd7a8203'"} -----> Running task in background
Web Interface
The plugin exposes a web UI for managing background tasks. You can list tasks, monitor their status, and cancel any running tasks. The web interface is available at /nino-queue-manager.
Methods for Users
-
append:- Used programmatically to add a task to the queue.
-
cancelTask:- Exposed via URL to cancel a specific task.
-
getTasks:- Exposed via URL to retrieve a list of all tasks.
The QueueManager is registered as a singleton via a service provider and is injectable across your Laravel application.
Scheduled Task
The queue daemon is scheduled using Laravel's scheduler:
$schedule->command('custom-queue:daemon')->everyTwoSeconds();
Ensure the cron job for php artisan schedule:run is set up.
Conclusion
This Custom Queue Manager provides a simple yet scalable solution for background task execution in Laravel, independent of the default queue system. It allows for easy management of tasks, logging, and web-based task management. By supporting multiple storage drivers and offering fine-grained control over task execution, it is flexible and highly customizable.
ninoslavjaric/queue-manager 适用场景与选型建议
ninoslavjaric/queue-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「queue-manager」 「laravel-package」 「background-jobs」 「task-queue」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ninoslavjaric/queue-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ninoslavjaric/queue-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ninoslavjaric/queue-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package for converting English numbers into Bangla digits, Bangla words, Bangla month names, and Bangla money format with an easy-to-use API.
Laravel table comments loader (part of Diplodocker project)
jitone-ai is a powerful FilamentPHP plugin that integrates AI-powered features directly into your Filament forms.
Laravel Queue Manager
Monitors the Craft queue manager for bottlenecks and send notifications emails
Laravel JWT auth service package
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-22