public function setUp()
 {
     parent::setUp();
     $config = SmashPigDatabaseTestConfiguration::instance();
     Context::initWithLogger($config);
     $this->db = DamagedDatabase::get();
     $this->db->createTable();
 }
 public function setUp()
 {
     parent::setUp();
     Context::initWithLogger(QueueTestConfiguration::instance());
     $this->queue = BaseQueueConsumer::getQueue('test');
     $this->queue->createTable('test');
     $damagedDb = DamagedDatabase::get();
     $damagedDb->createTable();
     $this->damaged = $damagedDb->getDatabase();
 }
 /**
  * Gets a fresh QueueConsumer
  *
  * @param string $queueName key of queue configured in data-store, must
  *  implement @see PHPQueue\Interfaces\AtomicReadBuffer.
  * @param int $timeLimit max number of seconds to loop, 0 for no limit
  * @param int $messageLimit max number of messages to process, 0 for all
  * @throws \SmashPig\Core\ConfigurationKeyException
  */
 public function __construct($queueName, $timeLimit = 0, $messageLimit = 0)
 {
     if (!is_numeric($timeLimit)) {
         throw new InvalidArgumentException('timeLimit must be numeric');
     }
     if (!is_numeric($messageLimit)) {
         throw new InvalidArgumentException('messageLimit must be numeric');
     }
     $this->queueName = $queueName;
     $this->timeLimit = intval($timeLimit);
     $this->messageLimit = intval($messageLimit);
     $this->backend = self::getQueue($queueName);
     if (!$this->backend instanceof AtomicReadBuffer) {
         throw new InvalidArgumentException("Queue {$queueName} is not an AtomicReadBuffer");
     }
     $this->damagedDb = DamagedDatabase::get();
 }
 /**
  * Do the actual work of the script.
  */
 public function execute()
 {
     $this->damagedDatabase = DamagedDatabase::get();
     $messages = $this->damagedDatabase->fetchRetryMessages($this->getOption('max-messages'));
     $stats = array();
     $config = Configuration::getDefaultConfig();
     foreach ($messages as $message) {
         $queueName = $message['original_queue'];
         // FIXME: getting it by alias, this will be annoying cos -new
         $queue = BaseQueueConsumer::getQueue($queueName);
         unset($message['original_queue']);
         $queue->push($message);
         $this->damagedDatabase->deleteMessage($message);
         if (isset($stats[$queueName])) {
             $stats[$queueName]++;
         } else {
             $stats[$queueName] = 1;
         }
     }
     foreach ($stats as $queueName => $count) {
         Logger::info("Requeued {$count} messages to {$queueName}.");
     }
 }