Exemplo n.º 1
0
 /**
  * @param $queue
  * @return QueueElement|bool
  */
 public function dequeue($queue)
 {
     $dbConnect = Db::getConnect();
     $dbConnect->beginTransaction();
     try {
         $query = Db::getConnect()->prepare("\n\t\t\t\tselect *\n\t\t\t\tfrom queue\n\t\t\t\twhere queue_name = :queue_name\n\t\t\t\tORDER  BY id\n\t\t\t\tlimit 1 FOR UPDATE\n\t \t\t");
         $query->bindParam(':queue_name', $queue);
         $query->execute();
         $elementArray = $query->fetchAll();
         $element = false;
         if (!empty($elementArray)) {
             $element = new QueueElement();
             $element->setQueueName($elementArray[0]['queue_name']);
             $element->setFileUrl($elementArray[0]['file_url']);
             $element->setStatus($elementArray[0]['status']);
             $queryDelete = Db::getConnect()->prepare("\n\t\t\t\t\tdelete from queue where id = :id\n\t \t\t\t");
             $queryDelete->bindParam(':id', $elementArray[0]['id']);
             $queryDelete->execute();
         }
         $dbConnect->commit();
     } catch (\Exception $e) {
         $dbConnect->rollBack();
         $element = false;
     }
     return $element;
 }
Exemplo n.º 2
0
 public function run($args)
 {
     $file = $args[0];
     /**
      * @param $handle
      * @return \Generator
      */
     function getStr($handle)
     {
         while (($buffer = fgets($handle)) !== false) {
             (yield $buffer);
         }
         fclose($handle);
     }
     $handle = self::getFileHandler($file, "r");
     $generator = getStr($handle);
     foreach ($generator as $url) {
         $newQueueElement = new QueueElement();
         $newQueueElement->setFileUrl(trim($url));
         (new DownloadQueue())->putElement($newQueueElement);
     }
 }