rcParallelTaskPlugin - 1.0.0

rcParallelTask Plugin

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source | Show as Markdown

rcParallelTask plugin

Overview

This plugin allow to create task that can fork for parallel processing. It provide an easy way to create as many child as you want and a simple queue and lock system.

Installation

To install sfPagerNavigationPlugin, type:

$ symfony plugin-install rcParallelTaskPlugin

Usage

Here is a simple example that show how to use this plugin :

<?php
class simpleParallelTask extends rcParallelTask {

    protected function configure() {

        $this->addOptions(
            array(
                new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'),
                new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
                new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
                // add your own options here
            )
        );

        $this->namespace           = 'symofny';
        $this->name                = 'simple-parallel';
        $this->briefDescription    = *;
        $this->detailedDescription = *;

    }


    protected function execute($arguments = array(), $options = array()) {

        // Start 2 child
        $this->startChildren(2);

        // initialize the database connection
        // Always start the database after starting the children because connexion can't be shared between multiple process
        $databaseManager = new sfDatabaseManager($this->configuration);
        $connection      = $databaseManager->getDatabase($options[? $options['connection']('connection']) : null)->getConnection();

        if ($this->iAmParent()) {
            for ($i=0; $i < 10; $i++) {
                $testArray = array('id' => $i);
                $this->addToQueue($testArray);
            }

            $this->logSection(date('Y-m-d H:i:s'), 'I sent everything');

            // Wait until queue is consume
            $this->waitForEmptyQueue();
        } else {
            // Child process
            while (($testArray = $this->getFromQueue())) {
                $this->logSection(date('Y-m-d H:i:s'), 'received : '.$testArray['id']);
            }
        }

   }

}
?>

License

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.