-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marc
committed
Nov 22, 2011
1 parent
64d5f2c
commit 3f73aaa
Showing
29 changed files
with
1,678 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class GearmanClientTestCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* Console Command configuration | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this->setName('gearman:client:test') | ||
->setDescription('Test') | ||
->addArgument('job', InputArgument::REQUIRED, 'job to execute') | ||
; | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input An InputInterface instance | ||
* @param OutputInterface $output An OutputInterface instance | ||
* | ||
* @return integer 0 if everything went fine, or an error code | ||
* | ||
* @throws \LogicException When this abstract class is not implemented | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$job = $input->getArgument('job'); | ||
$this->getContainer()->get('gearman')->doJob($job); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class GearmanJobDescribeCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* Console Command configuration | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this->setName('gearman:job:describe') | ||
->setDescription('Describe given job') | ||
->addArgument('job', InputArgument::REQUIRED, 'job to execute') | ||
; | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input An InputInterface instance | ||
* @param OutputInterface $output An OutputInterface instance | ||
* | ||
* @return integer 0 if everything went fine, or an error code | ||
* | ||
* @throws \LogicException When this abstract class is not implemented | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$job = $input->getArgument('job'); | ||
$worker = $this->getContainer()->get('gearman')->getWorker($job); | ||
|
||
$output->writeln(''); | ||
$output->writeln('<info> @Worker\className : '.$worker['className'].'</info>'); | ||
$output->writeln('<info> @Worker\fileName : '.$worker['fileName'].'</info>'); | ||
$output->writeln('<info> @Worker\namespace : '.$worker['namespace'].'</info>'); | ||
$output->writeln('<info> @Worker-jobsnumber : '.count($worker['jobs']).'</info>'); | ||
$output->writeln('<info> @Worker\description :</info>'); | ||
$output->writeln(''); | ||
$output->writeln('<comment> '.$worker['description'].'</comment>'); | ||
$output->writeln(''); | ||
$job = $worker['job']; | ||
$output->writeln('<info> @job\methodName : '.$job['methodName'].'</info>'); | ||
$output->writeln('<info> @job\callableName : '.$job['realCallableName'].'</info>'); | ||
$output->writeln('<info> @job\iterations : '.$job['iter'].'</info>'); | ||
$output->writeln('<info> @job\servers :</info>'); | ||
$output->writeln(''); | ||
foreach ($job['servers'] as $server) { | ||
$output->writeln('<comment> '.$server.'</comment>'); | ||
} | ||
$output->writeln(''); | ||
$output->writeln('<info> @job\description :</info>'); | ||
$output->writeln(''); | ||
$output->writeln('<comment> '.$job['description'].'</comment>'); | ||
$output->writeln(''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class GearmanJobExecuteCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* Console Command configuration | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this->setName('gearman:job:execute') | ||
->setDescription('Execute one job of worker') | ||
->addArgument('job', InputArgument::REQUIRED, 'Job to execute') | ||
; | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input An InputInterface instance | ||
* @param OutputInterface $output An OutputInterface instance | ||
* | ||
* @return integer 0 if everything went fine, or an error code | ||
* | ||
* @throws \LogicException When this abstract class is not implemented | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$dialog = $this->getHelperSet()->get('dialog'); | ||
if (!$input->getOption('no-interaction') && !$dialog->askConfirmation($output, '<question>This will execute asked worker?</question>', 'y')) { | ||
return; | ||
} | ||
|
||
$job = $input->getArgument('job'); | ||
$this->getContainer()->get('gearman.execute.job')->executeJob($job); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class GearmanJobListCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* Console Command configuration | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this->setName('gearman:job:list') | ||
->setDescription('List all Gearman Jobs') | ||
; | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input An InputInterface instance | ||
* @param OutputInterface $output An OutputInterface instance | ||
* | ||
* @return integer 0 if everything went fine, or an error code | ||
* | ||
* @throws \LogicException When this abstract class is not implemented | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$workers = $this->getContainer()->get('gearman')->getWorkers(); | ||
if (is_array($workers)) { | ||
foreach ($workers as $worker) { | ||
$output->writeln('<info> @'.$worker['className'].'</info>'); | ||
foreach($worker['jobs'] as $job) { | ||
$output->writeln('<comment> #'.$job['realCallableName'].'</comment>'); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* This is the class that validates and merges configuration from your app/config files | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('ulabox_gearman'); | ||
|
||
// Here you should define the parameters that are allowed to | ||
// configure your bundle. See the documentation linked above for | ||
// more information on that topic. | ||
|
||
return $treeBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||
*/ | ||
class UlaboxGearmanExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.yml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\Driver\Gearman; | ||
|
||
use Doctrine\Common\Annotations\Annotation; | ||
|
||
/** | ||
* Gearman annotations driver | ||
* | ||
* @author Marc Morera <marc@ulabox.com> | ||
*/ | ||
|
||
/** | ||
* @Annotation | ||
*/ | ||
final class Work extends Annotation { | ||
/** | ||
* Number of iterations specified for all jobs inside Work | ||
* | ||
* @var integer | ||
*/ | ||
public $name = NULL; | ||
|
||
/** | ||
* Description of Worker | ||
* | ||
* @var string | ||
*/ | ||
public $description = NULL; | ||
|
||
/** | ||
* Number of iterations specified for all jobs inside Work | ||
* | ||
* @var integer | ||
*/ | ||
public $iter = NULL; | ||
|
||
/** | ||
* Servers assigned for all jobs of this work to be executed | ||
* | ||
* @var mixed | ||
*/ | ||
public $servers = null; | ||
} | ||
|
||
/** | ||
* @Annotation | ||
*/ | ||
final class Job extends Annotation { | ||
/** | ||
* Method name to assign into job | ||
* | ||
* @var string | ||
*/ | ||
public $name = NULL; | ||
|
||
/** | ||
* Description of Job | ||
* | ||
* @var string | ||
*/ | ||
public $description = NULL; | ||
|
||
/** | ||
* Number of iterations specified for this job | ||
* | ||
* @var integer | ||
*/ | ||
public $iter = NULL; | ||
|
||
/** | ||
* Servers assigned for this job to be executed | ||
* | ||
* @var mixed | ||
*/ | ||
public $servers = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\Exceptions; | ||
|
||
/** | ||
* GearmanBundle can't find job specified as Gearman format Exception | ||
* | ||
* @author Marc Morera <marc@ulabox.com> | ||
*/ | ||
class JobDoesNotExistException extends \Exception | ||
{ | ||
|
||
/** | ||
* Construct method for Exception | ||
* | ||
* @param string $job Job name to be shown in Exception | ||
* @param integer $code | ||
* @param \Exception $previous | ||
*/ | ||
public function __construct($job, $code = 0, \Exception $previous = null) { | ||
|
||
$message = 'GearmanBundle can\'t find job with name ' . $job . PHP_EOL; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Ulabox\GearmanBundle\Exceptions; | ||
|
||
/** | ||
* GearmanBundle can't find settings into specified path Exception | ||
* | ||
* @author Marc Morera <marc@ulabox.com> | ||
*/ | ||
class NoSettingsFileExistsException extends \Exception | ||
{ | ||
|
||
/** | ||
* Construct method for Exception | ||
* | ||
* @param string $path | ||
* @param integer $code | ||
* @param \Exception $previous | ||
*/ | ||
public function __construct($path, $code = 0, \Exception $previous = null) { | ||
|
||
$message = 'GearmanBundle can\'t find settings file in path "' . $path . '"' . PHP_EOL; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
Oops, something went wrong.