943626451 / my-queue
A async-queue library built on top of swoole, flexable multi-consumer, coroutine supported.
Requires
- php: >=7.2
- ext-json: *
- ext-swoole: >=4.4
- illuminate/pipeline: ^6.16
- jeremeamia/superclosure: ^2.4
- monolog/monolog: ^2.0
- predis/predis: ^1.1
- psr/log: ^1.1
- symfony/console: ^4.3
Requires (Dev)
- phpunit/phpunit: ^8.3
- swoole/ide-helper: @dev
Suggests
- php: >=7.3
- dev-master
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- dev-optimize/failed-job-storage
- dev-pref/connection
- dev-fix/coroutine-exception-catching
- dev-feature/dashboard
- dev-feature/job-middleware
- dev-master-dev
- dev-pref/logger
- dev-pref/docs
This package is not auto-updated.
Last update: 2024-12-16 10:20:38 UTC
README
A async-queue library built on top of swoole, flexable multi-consumer, coroutine supported. 中文说明
Feature
- Default Redis driver
- Delayed job
- Custom job retries and times
- Custom failed callback
- Job middleware
- Queue snapshot event
- Concurrent processing, flexable multi-worker
- Worker coroutine support
- Beautiful dashboard
Required
- PHP 7.2+
- Swoole 4.4+
- Redis 3.2+ (redis driver)
Install
composer require littlesqx/aint-queue -vvv
Usage
Config
By default, aint-queue will require config/aint-queue.php
as default config. If not exist, /vendor/littlesqx/aint-queue/src/Config/config.php
will be the final config file.
<?php use Littlesqx\AintQueue\Driver\Redis\Queue as RedisQueue; use Littlesqx\AintQueue\Logger\DefaultLogger; return [ // channel_name => [...config] 'default' => [ 'driver' => [ 'class' => RedisQueue::class, 'connection' => [ 'host' => '127.0.0.1', 'port' => 6379, 'database' => '0', // 'password' => 'password', ], ], 'logger' => [ 'class' => DefaultLogger::class, 'options' => [ 'level' => \Monolog\Logger::DEBUG, ], ], 'pid_path' => '/var/run/aint-queue', 'consumer' => [ 'sleep_seconds' => 1, 'memory_limit' => 96, 'dynamic_mode' => true, 'capacity' => 6, 'flex_interval' => 5 * 60, 'min_worker_number' => 5, 'max_worker_number' => 30, 'max_handle_number' => 0, ], 'job_snapshot' => [ 'interval' => 5 * 60, 'handler' => [], ], ], ];
All the options:
Push job
You can use it in your project running via fpm/cli.
<?php use Littlesqx\AintQueue\Driver\DriverFactory; $queue = DriverFactory::make($channel, $options); // push a job $queue->push(function () { echo "Hello aint-queue\n"; }); // push a delay job $closureJob = function () { echo "Hello aint-queue delayed\n"; }; $queue->push($closureJob, 5); // And class job are allowed. // 1. Create a class which implements JobInterface, you can see the example in `/example`. // 2. Noted that job pushed should be un-serialize by queue-listener, // it means queue-pusher and queue-listener are required to in the same project. // 3. You can see more examples in `example` directory.
Manage Queue
We recommend that using Supervisor
to monitor and control the listener.
vendor/bin/aint-queue
AintQueue Console Tool Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: help Displays help for a command list Lists commands queue queue:clear Clear the queue. queue:dashboard Start http server for dashboard. queue:reload-failed Reload all the failed jobs onto the waiting queue. queue:status Get the execute status of specific queue. worker worker:listen Listen the queue. worker:reload Reload worker for the queue. worker:run Run the specific job. worker:stop Stop listening the queue.
Testing
composer test
Contributing
You can contribute in one of three ways:
- File bug reports using the issue tracker.
- Answer questions or fix bugs on the issue tracker.
- Contribute new features or update the wiki.
The code contribution process is not very formal. You just need to make sure that you follow the PSR-2, PSR-12 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.
License
MIT