Exemplo n.º 1
0
 /**
  * @param string $worker
  * @param string $queue
  *
  * @return Job
  *
  * @throws \de\detert\sebastian\slimline\db\Exception_NotFound
  * @throws Exception_StillRunning
  */
 public function getNextJob($worker, $queue)
 {
     $job = $this->getRunningJob($worker);
     if (!empty($job)) {
         throw new Exception_StillRunning();
     }
     $sql = "\n            UPDATE\n                `queue`\n            SET\n                `worker` = :worker\n            WHERE\n                `start` <= NOW() AND\n                `name` = :name AND\n                `worker` = 0\n            ORDER BY `start` ASC LIMIT 1";
     $this->db->query($sql, array('worker' => $worker, 'name' => $queue));
     if ($this->db->getAffectedRows()) {
         $job = $this->getRunningJob($worker);
     }
     if (empty($job)) {
         throw new Exception_NoJobFound();
     }
     return $job;
 }
Exemplo n.º 2
0
 /**
  * testShouldGetAffectedRows
  *
  * @param $debug
  *
  * @dataProvider getResponseDebugSql
  * @covers de\detert\sebastian\slimline\db\Handler::getAffectedRows
  */
 public function testShouldGetAffectedRows(Response_Debug_Sql $debug = null)
 {
     $handler = new Handler($this->dbConfig);
     if (!is_null($debug)) {
         $handler->setDebugResponse($debug);
     }
     $sql = 'CREATE TABLE IF NOT EXISTS `foo` (`id` INT(20))';
     $this->handler->query($sql);
     $sql = 'INSERT INTO `foo` VALUES (?), (?)';
     $params = array(1, 2);
     $handler->query($sql, $params);
     $this->assertEquals(2, $handler->getAffectedRows());
 }