Download the PHP package ninoslavjaric/queue-manager without Composer
On this page you can find all versions of the php package ninoslavjaric/queue-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ninoslavjaric/queue-manager
More information about ninoslavjaric/queue-manager
Files in ninoslavjaric/queue-manager
Package queue-manager
Short Description A Laravel-based queue management system with background job support.
License MIT
Informations about the package queue-manager
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:
-
Run migrations to set up the necessary database tables:
- Add the scheduler to your crontab to run the queue daemon:
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:
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
limit
parameter.
- 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:
- 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:
- Task execution:
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:
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.