Skip to content

pmiroslawski/supervisor-controller-bundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Supervisor Controller Bundle

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

Installation

  1. Require the bundle and a PSR 7/17 implementation with Composer:

    composer require pmiroslawski/supervisor-controller-bundle
  2. 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
  3. 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.