Created
May 30, 2014 10:04
-
-
Save pensiero/08444e1608f1e76047f6 to your computer and use it in GitHub Desktop.
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
<?php | |
$job = $this->_jobManager->get('Toms\Job\VisitJob'); | |
$this->_queue->push($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
<?php | |
/** | |
* This is the config file for SlmQueue. Just drop this file into your config/autoload folder (don't | |
* forget to remove the .dist extension from the file), and configure it as you want | |
*/ | |
return array( | |
'slm_queue' => array( | |
/** | |
* Parameters for the worker. It defines some criterias that can be reached before the | |
* worker stops to process any other jobs | |
*/ | |
'worker' => array( | |
/** | |
* Specify how many jobs can be processed by a worker until it stops (default to 100 000) | |
*/ | |
// 'max_runs' => 100000, | |
/** | |
* Specifiy the max memory (in bytes) that can be used by the worker before it stops (default to 100 MB) | |
*/ | |
// 'max_memory' => 100 * 1024 * 1024 | |
), | |
/** | |
* Allow to configure a specific queue. | |
* | |
* Available options depends on the queue factory | |
*/ | |
'queues' => array( | |
'default' => array( | |
'sleep_when_idle' => 1 | |
) | |
), | |
/** | |
* Allow to configure dependencies for jobs that are pulled from any queue. This works like any other | |
* PluginManager in Zend Framework 2. For instance, if you want to inject something into every job using | |
* a factory, just adds an element into the "factories" array, with the key being the FQCN of the job, | |
* and the value the factory: | |
* | |
* 'job_manager' => array( | |
* 'factories' => array( | |
* 'Application\Job\UserJob' => 'Application\Factory\UserJobFactory' | |
* ) | |
* ) | |
* | |
* Therefore, the job will be created through the factory (the identifier and content of the job will be | |
* automatically set after creation). Note that this plugin manager is configured as such it automatically | |
* add any unknown classes to the invokables list. This means you should only add factories and/or abstract | |
* factories here. | |
*/ | |
'job_manager' => array( | |
'factories' => array( | |
'Toms\Job\VisitJob' => 'Toms\JobFactory\VisitJobFactory' | |
) | |
), | |
/** | |
* Allow to add queues. You need to have at least one queue. This works like any other PluginManager in | |
* Zend Framework 2. For instance, if you have a queue whose name is "email", you can add it as an | |
* invokable this way: | |
* | |
* 'queue_manager' => array( | |
* 'invokables' => array( | |
* 'email' => 'Application\Queue\MyQueue' | |
* ) | |
* ) | |
* | |
* Please note that you can find built-in factories for several queue systems (Beanstalk, Amazon Sqs...) | |
* in SlmQueueSqs and SlmQueueBeanstalk | |
*/ | |
'queue_manager' => array( | |
'factories' => array( | |
'default' => 'SlmQueueDoctrine\Factory\DoctrineQueueFactory' | |
) | |
) | |
), | |
); |
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
<?php | |
namespace Toms\Job; | |
use SlmQueue\Job\AbstractJob; | |
use Doctrine\ORM\EntityManager; | |
class VisitJob extends AbstractJob { | |
/** | |
* @var EntityManager | |
*/ | |
protected $_em; | |
/** | |
* @param EntityManager $em | |
*/ | |
public function __construct(EntityManager $em) { | |
$this->_em = $em; | |
} | |
public function execute() { | |
echo 'Hello World'; | |
} | |
} |
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
<?php | |
namespace MyModule\Factory; | |
use Zend\ServiceManager\FactoryInterface; | |
use Zend\ServiceManager\ServiceLocatorInterface; | |
use Toms\Job\VisitJob; | |
class VisitJobFactory implements FactoryInterface { | |
public function createService(ServiceLocatorInterface $serviceLocator) { | |
$em = $serviceLocator->getServiceLocator()->get('doctrine.entitymanager.orm_default'); | |
return new VisitJob($em); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment