Просмотр исходного кода

#3546 transcoding queue should check periodically if video is really processing, sometimes process could be just ended unexpectedly

Alex Trofimov 5 лет назад
Родитель
Сommit
1817d5c34d
3 измененных файлов с 20 добавлено и 3 удалено
  1. 2 1
      inc/classes/BxDolTranscoder.php
  2. 17 2
      inc/classes/BxDolTranscoderQuery.php
  3. 1 0
      install/sql/system.sql

+ 2 - 1
inc/classes/BxDolTranscoder.php

@@ -428,7 +428,8 @@ class BxDolTranscoder extends BxDolFactory implements iBxDolFactoryObject
         $sExtChange = false;
         $bRet = true;
 
-        $this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_PROCESSING, '', gethostname());
+        $iPID = function_exists('posix_getpid') ? posix_getpid() : 0;
+        $this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_PROCESSING, '', gethostname(), '', '', '', $iPID);
 
         do {
 

+ 17 - 2
inc/classes/BxDolTranscoderQuery.php

@@ -150,6 +150,19 @@ class BxDolTranscoderQuery extends BxDolDb
     {
         $oDb = BxDolDb::getInstance();
 
+        // check if files which are processing are alive
+        if (function_exists('posix_kill')) {
+            $sQuery = $oDb->prepare("SELECT * FROM `" . self::TABLE_QUEUE . "` WHERE `server` = ? AND `status` = 'processing'", $sServer);
+            if ($a = $oDb->getAll($sQuery)) {
+                foreach ($a as $r) {
+                    $o = BxDolTranscoder::getObjectInstance($r['transcoder_object']);
+                    if ($o && $r['pid'] && !posix_kill($r['pid'], 0)) {
+                        $o->getDb()->updateQueueStatus($r['file_id_source'], BX_DOL_QUEUE_FAILED, "transcoding process died unexpectedly\n");
+                    }
+                }
+            }
+        }
+
         // delete items which are stuck in processing status
         $sQuery = $oDb->prepare("DELETE FROM `" . self::TABLE_QUEUE . "` WHERE `server` = ? AND `status` = ? AND `changed` < ? - ?", $sServer, BX_DOL_QUEUE_PROCESSING, time(), BX_DOL_QUEUE_PRUNE_PROCESSING);
         $oDb->query($sQuery);
@@ -210,12 +223,12 @@ class BxDolTranscoderQuery extends BxDolDb
     public function addToQueue ($mixedId, $sFileUrl, $iProfileId)
     {
         if (!$this->_sTableQueue)
-            return false;
+            return false;        
         $sQuery = $this->prepare("INSERT INTO `" . $this->_sTableQueue . "` SET `transcoder_object` = ?, `profile_id` = ?, `file_url_source` = ?, `file_id_source` = ?, `status` = ?, `added` = ?, changed = ?", $this->_aObject['object'], $iProfileId, $sFileUrl, $mixedId, BX_DOL_QUEUE_PENDING, time(), time());
         return $this->query($sQuery);
     }
 
-    public function updateQueueStatus ($mixedId, $sStatus, $sLog = '', $sServer = '', $mixedIdResult = '', $sFileUrlResult = '', $sFileExtResult = '')
+    public function updateQueueStatus ($mixedId, $sStatus, $sLog = '', $sServer = '', $mixedIdResult = '', $sFileUrlResult = '', $sFileExtResult = '', $iPID = 0)
     {
         if (!$this->_sTableQueue)
             return false;
@@ -229,6 +242,8 @@ class BxDolTranscoderQuery extends BxDolDb
 			$aSet['log'] = $sLog;
         if($sServer)
         	$aSet['server'] = $sServer;
+        if($iPID)
+            $aSet['pid'] = $iPID;
 		if($mixedIdResult && $sFileUrlResult)
 			$aSet = array_merge($aSet, array(
 				'file_id_result' => $mixedIdResult,

+ 1 - 0
install/sql/system.sql

@@ -4946,6 +4946,7 @@ CREATE TABLE IF NOT EXISTS `sys_transcoder_queue` (
   `file_id_result` int(11) NOT NULL,
   `server` varchar(255) NOT NULL,
   `status` enum('pending','processing','complete','failed','delete') NOT NULL,
+  `pid` int(10) UNSIGNED NOT NULL DEFAULT '0',
   `added` int(11) NOT NULL,
   `changed` int(11) NOT NULL,
   `log` text NOT NULL,