worker-manager
Application check rabbitMQ queue message rate and supervisor worker status.
If queue is empty - app will stop workers. Whet get new message - will start worker(s).
In supervisor configuration need to be configured max count of workers., (*1)
Installation, (*2)
composer require artaxmax/worker-manager
Usage
Create console file (app/console.php):, (*3)
<?php
set_time_limit(0);
require_once __DIR__.'/../vendor/autoload.php'; // include composer autoload.php file
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use WorkerManager\Command\WorkerCommand;
$application = new Application();
$application->add(new WorkerCommand()); // add worker command
$application->run(new ArgvInput()); // run application
Create config YML file (config.yml), (*4)
-
Configure RabbitMQ api:, (*5)
worker_manager:
rabbitmq:
rabbit1:
name: rabbit1
host: localhost
username: username
password: password
-
Configure supervisor:, (*6)
worker_manager:
supervisor1:
name: supervisor1
server: http://localhost:8081
username: username
password: password
config: /.../supervisor.conf
max_worker_count: 10
-
Configure each one worker:, (*7)
worker_manager:
worker1:
name: worker1
queue: worker1-queue
vhost: /
min_count: 1
max_count: 2
Register config file, (*8)
<?php
use WorkerManager\Service\ConfigManager;
...
ConfigManager::register(__DIR__.'/config/config.yml');
Run application:, (*9)
php app/console.php worker-manager:start
You can add your own logging class. It should implement WorkerManager\Interfaces\LoggerInterface
interface:, (*10)
<?php
...
$logger = new YourLogger();
$command = new WorkerCommand();
$command->setLogger($logger);
...
$application->add($command);
...