pmiroslawski / supervisor-controller-bundle
PHP Symfony Bundle which manage of supervisor processes
Installs: 24
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >7.4
- helppc/supervisor-bundle: ^1
- symfony/config: ^5
- symfony/console: ^5
- symfony/event-dispatcher: ^5.3
- symfony/framework-bundle: ^5
- symfony/yaml: ^5
Requires (Dev)
- phpstan/phpstan: ^0.12.96
- symfony/var-dumper: ^5
README
Symfony bundle which manages supervisor processes automatically based on given thresholds configuration. Bundle is implemented using the helppc/supervisor-bundle library.
Example of use
Check this: pmiroslawski/supervisor-controller-demo to see the bundle in action.
Requirements
- PHP 7.4 or greater
- Symfony 5.x
Installation
-
Require the bundle and a PSR 7/17 implementation with Composer:
composer require pmiroslawski/supervisor-controller-bundle
-
Create the bundle configuration file under
config/packages/bit9_supervisor_controller.yaml
. Here is a reference configuration file:bit9_supervisor_controller: queues: - name: messages consumer: message_consumer numprocs: 50 # run 50 if more than 10000 thresholds: - messages: 100 # run 3 processes if less than 100 elements in queue num: 3 - messages: 1000 # run 5 processes if less than 1000 elements in queue num: 5 - messages: 10000 # run 10 processes if less than 10000 elements in queue num: 10
-
Enable the bundle in
config/bundles.php
by adding it to the array:Bit9\SupervisorControllerBundle\Bit9SupervisorControllerBundle::class => ['all' => true],
Usage
The bundle provides an extra public service which can number of processes for spcified queue
Bit9\SupervisorControllerBundle\Service\Queue\Monitor
That service has only one method execute
which get as arguments name of the queue and current number of messages in given queue. Base on thresholds defined in configuration for specified queue service starting extra processes or stoping already running one which consume a given queue.
Above service has been implemented in supervisor:queue:monitor
command also delivered in this bundle.
Additionally, bundle provides bunch of extra commands in supervisor namespace which can help to manage configuration and let you easy execute basic commands:
supervisor-controller
supervisor-controller:program:status Get the supervisor program prcocesses statuses
supervisor-controller:program:update Run given number of processes for specified program
supervisor-controller:queue:check Check a specified queue to see number of elements.
supervisor-controller:queue:conductor Command run/stop some number of processes based on passed queue's elements number.
supervisor-controller:queue:config Get configuration for the given queue name
supervisor-controller:queue:watchdog Command checks queue and passed readed number of elements into queue conductor.
Events
The bundle provides events and dispatches them in some specified situations. There are two groups of events
When bundle does start/stop processes, one of the below events is dispatching:
Bit9\SupervisorControllerBundle\Event\ProcessesStartedEvent
Bit9\SupervisorControllerBundle\Event\ProcessesStoppedEvent
Both of them contain:
- consumer name (the group name)
- number of started/stopped processes
- total number of running processes (after operation)
When bundle does start/stop a specified single process, one of the below events is dispatching:
Bit9\SupervisorControllerBundle\Event\ProcessStartedEvent
Bit9\SupervisorControllerBundle\Event\ProcessStoppedEvent
Both of them contain:
- exact process name (the same as in supervisor)
- timestamp of started/stopped given process
License
The MIT License (MIT). Please see License File for more information.