public function setUp()
 {
     parent::setUp();
     $this->createDb();
     $options = new DoctrineOptions();
     // we want tests to run as fast as possible
     $options->setSleepWhenIdle(0);
     $this->queue = new DoctrineQueue($this->getEntityManager()->getConnection(), $options, 'some-queue-name', ServiceManagerFactory::getServiceManager()->get('SlmQueue\\Job\\JobPluginManager'));
 }
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator, $name = '', $requestedName = '')
 {
     $parentLocator = $serviceLocator->getServiceLocator();
     $config = $parentLocator->get('Config');
     $queuesOptions = $config['slm_queue']['queues'];
     $options = isset($queuesOptions[$requestedName]) ? $queuesOptions[$requestedName] : array();
     $queueOptions = new DoctrineOptions($options);
     /** @var $connection \Doctrine\DBAL\Connection */
     $connection = $parentLocator->get($queueOptions->getConnection());
     $jobPluginManager = $parentLocator->get('SlmQueue\\Job\\JobPluginManager');
     $queue = new DoctrineQueue($connection, $queueOptions, $requestedName, $jobPluginManager);
     return $queue;
 }
 /**
  * Cleans old jobs in the table according to the configured lifetime of successful and failed jobs.
  */
 protected function purge()
 {
     if ($this->options->getBuriedLifetime() > static::LIFETIME_UNLIMITED) {
         $buriedLifetime = $this->parseOptionsToDateTime(array('delay' => -($this->options->getBuriedLifetime() * 60)));
         $delete = 'DELETE FROM ' . $this->options->getTableName() . ' ' . 'WHERE finished < ? AND status = ? AND queue = ? AND finished IS NOT NULL';
         $this->connection->executeUpdate($delete, array($buriedLifetime, static::STATUS_BURIED, $this->getName()), array(Type::DATETIME, Type::INTEGER, Type::STRING));
     }
     if ($this->options->getDeletedLifetime() > static::LIFETIME_UNLIMITED) {
         $deletedLifetime = $this->parseOptionsToDateTime(array('delay' => -($this->options->getDeletedLifetime() * 60)));
         $delete = 'DELETE FROM ' . $this->options->getTableName() . ' ' . 'WHERE finished < ? AND status = ? AND queue = ? AND finished IS NOT NULL';
         $this->connection->executeUpdate($delete, array($deletedLifetime, static::STATUS_DELETED, $this->getName()), array(Type::DATETIME, Type::INTEGER, Type::STRING));
     }
 }