コード例 #1
0
 private function closeConvert(KalturaBatchJob $job, KalturaConvertJobData $data)
 {
     KalturaLog::debug("fetchStatus({$job->id})");
     if ($job->queueTime + $this->taskConfig->params->maxTimeBeforeFail < time()) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::CLOSER_TIMEOUT, 'Timed out', KalturaBatchJobStatus::FAILED);
     }
     if ($job->jobSubType == KalturaConversionEngineType::ENCODING_COM) {
         $parseEngine = new KParseEngineEncodingCom($this->taskConfig);
         $errMessage = null;
         $status = $parseEngine->parse($data, $errMessage);
         if ($errMessage == $job->message) {
             $errMessage = null;
         }
         $log = $parseEngine->getLogData();
         if ($log && strlen($log)) {
             $this->kClient->batch->logConversion($data->flavorAssetId, $log);
         }
         if ($status == KalturaBatchJobStatus::FINISHED) {
             $updateData = new KalturaConvertJobData();
             $updateData->destFileSyncRemoteUrl = $data->destFileSyncRemoteUrl;
             $this->updateJob($job, $errMessage, KalturaBatchJobStatus::ALMOST_DONE, 90, $updateData);
         } else {
             return $this->closeJob($job, null, null, $errMessage, $status);
         }
     }
     if ($job->jobSubType == KalturaConversionEngineType::KALTURA_COM) {
         // TODO
         // fetch status from kaltura.com
         // if status is not ready - return
         // $data->destFileSyncRemoteUrl = "http://kaltura.com/...";
     }
     if ($job->executionAttempts > 1) {
         if (strlen($data->destFileSyncLocalPath) && file_exists($data->destFileSyncLocalPath)) {
             return $this->moveFile($job, $data);
         }
     }
     // creates a temp file path
     $uniqid = uniqid('convert_');
     $data->destFileSyncLocalPath = "{$this->localTempPath}/{$uniqid}";
     $err = null;
     if (!$this->fetchFile($data->destFileSyncRemoteUrl, $data->destFileSyncLocalPath, $err)) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::REMOTE_DOWNLOAD_FAILED, $err, KalturaBatchJobStatus::ALMOST_DONE);
     }
     $this->fetchFile($data->destFileSyncRemoteUrl . '.log', $data->destFileSyncLocalPath . '.log');
     return $this->moveFile($job, $data);
 }
 private function closeConvert(KalturaBatchJob $job, KalturaConvertJobData $data)
 {
     KalturaLog::debug("fetchStatus({$job->id})");
     if ($job->queueTime + $this->taskConfig->params->maxTimeBeforeFail < time()) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::CLOSER_TIMEOUT, 'Timed out', KalturaBatchJobStatus::FAILED);
     }
     if ($job->jobSubType == KalturaConversionEngineType::ENCODING_COM) {
         $parseEngine = new KParseEngineEncodingCom($this->taskConfig);
         $errMessage = null;
         $status = $parseEngine->parse($data, $errMessage);
         if ($errMessage == $job->message) {
             $errMessage = null;
         }
         $log = $parseEngine->getLogData();
         //removing unsuported XML chars
         $log = preg_replace('/[^\\t\\n\\r\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]/u', '', $log);
         if ($log && strlen($log)) {
             try {
                 $this->kClient->batch->logConversion($data->flavorAssetId, $log);
             } catch (Exception $e) {
                 KalturaLog::err("Log conversion: " . $e->getMessage());
             }
         }
         if ($status == KalturaBatchJobStatus::FINISHED) {
             $updateData = new KalturaConvertJobData();
             $updateData->destFileSyncRemoteUrl = $data->destFileSyncRemoteUrl;
             $this->updateJob($job, $errMessage, KalturaBatchJobStatus::ALMOST_DONE, 90, $updateData);
         } else {
             return $this->closeJob($job, null, null, $errMessage, $status);
         }
     }
     if ($job->executionAttempts > 1) {
         if (strlen($data->destFileSyncLocalPath) && file_exists($data->destFileSyncLocalPath)) {
             return $this->moveFile($job, $data);
         }
     }
     // creates a temp file path
     $uniqid = uniqid('convert_');
     $data->destFileSyncLocalPath = "{$this->localTempPath}/{$uniqid}";
     $err = null;
     if (!$this->fetchFile($data->destFileSyncRemoteUrl, $data->destFileSyncLocalPath, $err)) {
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::REMOTE_DOWNLOAD_FAILED, $err, KalturaBatchJobStatus::ALMOST_DONE);
     }
     $this->fetchFile($data->logFileSyncRemoteUrl, $data->logFileSyncLocalPath);
     return $this->moveFile($job, $data);
 }