2017 © Pedro Peláez
 

yii2-extension yii2-smart-task-processor

Smart Task Processor with ability to live or deferred processing tasks through any of availabled transports: nats, rabbitmq, mongo, native socket

image

dostoevskiy-spb/yii2-smart-task-processor

Smart Task Processor with ability to live or deferred processing tasks through any of availabled transports: nats, rabbitmq, mongo, native socket

  • Monday, October 2, 2017
  • by dostoevskiy-spb
  • Repository
  • 1 Watchers
  • 0 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Smart Task Processor

Smart Task Processor with ability to live or deferred processing tasks through any of availabled transports: nats, rabbitmq, mongo, native socket, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist dostoevskiy-spb/yii2-smart-task-processor "*"

or add, (*4)

"dostoevskiy-spb/yii2-smart-task-processor": "*"

to the require section of your composer.json file., (*5)

Usage

Once the extension is installed, simply use it in your code by adding actions to any of yours controllers :, (*6)

    /** Listner action **/        
    public function actionTaskProcessor() {
        global $argv;
        $old     = $argv;
        $argv[0] = $old[1];
        $argv[1] = $argv[2];
        if (array_key_exists(3, $argv)) {
            $argv[2] = $argv[3];
        }
        $processor = Yii::$app->processor;
        $processor->listen();
    }

    /** Runner deffered task processor
     * 
     * @param string $task task name form config
     */
    public function actionTaskProcessorRun($task) {
        global $argv;
        $old     = $argv;
        $argv[0] = $old[1];
        if (array_key_exists(3, $argv)) {
            $argv[1] = $argv[3];
        }
        if (array_key_exists(4, $argv)) {
            $argv[2] = $argv[4];
        }
        $processor = Yii::$app->processor;
        $processor->run($task);
    }    

example config:, (*7)

'processor'  => [
            'class'          => 'dostoevskiy\processor\SmartTaskProcessor',
            'tasksConfig'    => [
                'statistics'   => [
                    'class'          => 'console\components\taskProcessor\statistics\StatsProcessor',
                    'type'           => 'deferred',
                    'threads'        => 3,
                    'storage'        => 'rabbit',
                    'storageOptions' => [
                        'durable'    => false,
                        'queue'      => 'statistics',
                        'persistent' => false
                    ],
                ],
                'linkDelivery' => [
                    'class'          => 'console\components\taskProcessor\links\LinksDelivery',
                    'type'           => 'live',
                    'threads'        => 1,
                    'transactional'  => true,
                ],
            ],
            'storagesConfig' => [
                'rabbit' => [
                    'type'        => 'rabbit',
                    'credentials' => [
                        'host'     => 'localhost',
                        'port'     => 5672,
                        'user'     => 'guest',
                        'password' => 'guest',
                        'vhost'    => '/',
                    ],
                ],
            ],
            'listnerConfig'  => [
                'class'            => 'dostoevskiy\processor\src\classes\Listner',
                'type'             => 'tcp',
                'host'             => '0.0.0.0',
                'port'             => '8181',
                'threads'          => 8,
                'servicesToReload' => ['db', 'mongo', 'rabbit'],
            ],
        ],

The Versions

02/10 2017

dev-master

9999999-dev

Smart Task Processor with ability to live or deferred processing tasks through any of availabled transports: nats, rabbitmq, mongo, native socket

  Sources   Download

Apache-2.0

The Requires

 

by Pavel Lamzin

task task processor