Skip to content

Commit

Permalink
#3544 Logging for transcoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Trofimov committed Oct 22, 2021
1 parent 9b6f820 commit 6e4f8ff
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 25 deletions.
89 changes: 67 additions & 22 deletions inc/classes/BxDolTranscoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,25 @@ static public function processCompleted ()
$sFileData = bx_file_get_contents ($aQueue['file_url_result']);
if (false === $sFileData) {
$o->getDb()->updateQueueStatus($aQueue['file_id_source'], BX_DOL_QUEUE_FAILED, "download file failed: {$aQueue['file_url_result']}\n");
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: processCompleted failed, get transcoded file from URL ({$aQueue['file_url_result']}) failed");
continue;
}

$sTmpFile = $o->getTmpFilename ('.' . $aQueue['file_ext_result']);
if (!file_put_contents($sTmpFile, $sFileData)) {
$o->getDb()->updateQueueStatus($aQueue['file_id_source'], BX_DOL_QUEUE_FAILED, "store downloaded file failed\n");
@unlink($sTmpFile);
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: processCompleted failed, store transcoded file to tmp file ({$sTmpFile}) failed");
continue;
}

// store downloaded file in final storage
if ($o->storeTranscodedFile($aQueue['file_id_source'], $sTmpFile, $aQueue['profile_id']))
if ($o->storeTranscodedFile($aQueue['file_id_source'], $sTmpFile, $aQueue['profile_id'])) {
$o->getDb()->updateQueueStatus($aQueue['file_id_source'], BX_DOL_QUEUE_DELETE); // mark to delete it (deletion is performed on the server where it was transcoded)
else
} else {
$o->getDb()->updateQueueStatus($aQueue['file_id_source'], BX_DOL_QUEUE_FAILED, "store file failed:\n" . $o->getLog());
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: processCompleted failed, store transcoded file ({$aQueue['file_id_source']}) in final storage failed: " . $o->getLog());
}

// delete tmp local file
@unlink($sTmpFile);
Expand Down Expand Up @@ -285,13 +289,17 @@ public function onDeleteFileOrig($mixedHandler)

// delete main file
$iFileId = $this->_oDb->getFileIdByHandler($mixedHandler);
if ($iFileId && !$this->_oStorage->deleteFile($iFileId))
if ($iFileId && !$this->_oStorage->deleteFile($iFileId)) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: onDeleteFileOrig failed for handler ({$mixedHandler}) delete failed");
return false;
}

// delete retina file
$iFileId = $this->_oDb->getFileIdByHandler($mixedHandler . $this->_sRetinaSuffix);
if ($iFileId && !$this->_oStorage->deleteFile($iFileId))
if ($iFileId && !$this->_oStorage->deleteFile($iFileId)) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: onDeleteFileOrig failed for handler ({$mixedHandler}) delete retina file failed");
return false;
}

return true;
}
Expand Down Expand Up @@ -364,21 +372,27 @@ public function getFileUrl($mixedHandler)
$mixedHandler = $this->processHandlerForRetinaDevice($mixedHandler);

$iFileId = $this->_oDb->getFileIdByHandler($mixedHandler);
if (!$iFileId)
if (!$iFileId) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: getFileUrl failed for handler ({$mixedHandler}) source file id wasn't found");
return false;
}

$aFile = $this->_oStorage->getFile($iFileId);
if (!$aFile)
if (!$aFile) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: getFileUrl failed for handler ({$mixedHandler}) source file wasn't found in the source storage");
return false;
}

if ($this->_aObject['atime_tracking'])
$this->_oDb->updateAccessTime($mixedHandler);

return $this->_oStorage->getFileUrlById($iFileId);
}

if ($this->_sQueueTable && !$this->addToQueue($mixedHandler)) // add file to queue (when queue is enabled) if it isn't transcoded yet
if ($this->_sQueueTable && !$this->addToQueue($mixedHandler)) { // add file to queue (when queue is enabled) if it isn't transcoded yet
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: getFileUrl failed for handler ({$mixedHandler}), can't add file to queue");
return false;
}

return $this->getFileUrlNotReady($mixedHandler);
}
Expand Down Expand Up @@ -589,6 +603,7 @@ public function deleteFromQueue ($mixedHandler)
$oStorage = BxDolStorage::getObjectInstance($this->_sQueueStorage);
if (!$oStorage->deleteFile($a['file_id_result'])) {
$this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_FAILED, $sErrMsg . $this->getLog());
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: deleteFromQueue failed for handler ({$mixedHandler}): " . $this->getLog());
return false;
}
}
Expand All @@ -603,6 +618,7 @@ public function storeTranscodedFile ($mixedHandler, $sTmpFile, $iProfileId)
$iFileId = $this->_oStorage->storeFileFromPath ($sTmpFile, $isPrivate, $iProfileId);
if (!$iFileId) {
$this->addToLog($this->_oStorage->getErrorString());
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeTranscodedFile failed for handler ({$mixedHandler}): " . $this->_oStorage->getErrorString());
return false;
}

Expand All @@ -626,6 +642,7 @@ protected function storeTranscodedFileInQueueStorage ($mixedHandler, $sTmpFile,
$iFileIdResult = $oStorage->storeFileFromPath ($sTmpFile, 1, 0);
if (!$iFileIdResult) {
$this->addToLog($oStorage->getErrorString());
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeTranscodedFileInQueueStorage failed for handler ({$mixedHandler}): " . $oStorage->getErrorString());
return false;
}

Expand Down Expand Up @@ -664,6 +681,8 @@ protected function applyFilter_Resize ($sFile, $aParams)
if (IMAGE_ERROR_SUCCESS == $o->resize($sFile))
return true;

bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: applyFilter_Resize failed for file ({$sFile}): " . $o->getError());

return false;
}

Expand Down Expand Up @@ -747,81 +766,107 @@ protected function getFilePath_Folder ($mixedHandler)
if (!file_exists($sPath))
$sPath = BX_DIRECTORY_PATH_ROOT . $sPath;

if (!file_exists($sPath))
if (!file_exists($sPath)) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: getFilePath_Folder failed, file ({$sPath}) doesn't exist for handler ({$mixedHandler})");
return false;
}

return $sPath;
}

protected function storeFileLocally_Folder ($mixedHandler)
{
$sPath = $this->getFilePath_Folder($mixedHandler);
if (!$sPath)
if (!$sPath) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Folder failed, source file ({$sPath}) doesn't exist for handler ({$mixedHandler})");
return false;
}

$sTmpFile = $this->getTmpFilename ($mixedHandler);
if (!copy($sPath, $sTmpFile))
if (!copy($sPath, $sTmpFile)) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Folder failed, copy from file ({$sPath}) to file ({$sTmpFile}) failed");
return false;
}

return $sTmpFile;
}

protected function storeFileLocally_Storage ($mixedHandler)
{
$oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']);
if (!$oStorageOriginal)
if (!$oStorageOriginal) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Storage failed, source storage({$this->_aObject['source_params']['object']}) isn't available");
return false;
}

$aFile = $oStorageOriginal->getFile($mixedHandler);
if (!$aFile)
if (!$aFile) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Storage failed, file({$mixedHandler}) wasn't found in source storage ({$this->_aObject['source_params']['object']})");
return false;
}

$sUrl = $oStorageOriginal->getFileUrlById($mixedHandler);
if (!$sUrl)
if (!$sUrl) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Storage failed, file({$mixedHandler}) wasn't found in source storage ({$this->_aObject['source_params']['object']})");
return false;
}

$sFileData = bx_file_get_contents ($sUrl);
if (false === $sFileData)
$sFileData = bx_file_get_contents ($sUrl, [], 'get', []);
if (false === $sFileData) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Storage failed, getting file from URL({$sUrl}) failed");
return false;
}

$sTmpFile = $this->getTmpFilename ($aFile['file_name']);
if (!file_put_contents($sTmpFile, $sFileData))
if (!file_put_contents($sTmpFile, $sFileData)) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Storage failed, file save failed ({$sTmpFile})");
return false;
}

return $sTmpFile;
}

protected function storeFileLocally_Queue ($mixedHandler)
{
$aQueue = $this->_oDb->getFromQueue($mixedHandler);
if (!$aQueue || !$aQueue['file_url_source'])
if (!$aQueue || !$aQueue['file_url_source']) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Queue failed, file ({$mixedHandler}) wasn't found in queue");
return false;
}

$sFileData = bx_file_get_contents ($aQueue['file_url_source']);
if (false === $sFileData)
$sFileData = bx_file_get_contents ($aQueue['file_url_source'], [], 'get', []);
if (false === $sFileData) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Queue failed, getting file from URL({$aQueue['file_url_source']}) failed");
return false;
}

$sTmpFile = $this->getTmpFilename ($mixedHandler);
if (!file_put_contents($sTmpFile, $sFileData))
if (!file_put_contents($sTmpFile, $sFileData)) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: storeFileLocally_Queue failed, file save failed ({$sTmpFile})");
return false;
}

return $sTmpFile;
}

protected function getOrigFileUrl_Folder ($mixedHandler)
{
$sPath = $this->_aObject['source_params']['path'] . $mixedHandler;
if (!file_exists(BX_DIRECTORY_PATH_ROOT . $sPath))
if (!file_exists(BX_DIRECTORY_PATH_ROOT . $sPath)) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: getOrigFileUrl_Folder failed, source file ({$sPath}) doesn't exist");
return false;
}

return BX_DOL_URL_ROOT . $sPath;
}

protected function getOrigFileUrl_Storage ($mixedHandler)
{
$oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']);
if (!$oStorageOriginal)
if (!$oStorageOriginal) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: getOrigFileUrl_Storage failed, source storage ({$this->_aObject['source_params']['object']}) doesn't exist");
return false;
}

return $oStorageOriginal->getFileUrlById($mixedHandler);
}
Expand Down
2 changes: 2 additions & 0 deletions inc/classes/BxDolTranscoderImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ protected function applyFilter_Grayscale ($sFile, $aParams)
if (IMAGE_ERROR_SUCCESS == $o->grayscale($sFile))
return true;

bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: applyFilter_Grayscale failed for file ({$sFile}): " . $o->getError());

return false;
}

Expand Down
8 changes: 6 additions & 2 deletions inc/classes/BxDolTranscoderVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,15 @@ protected function _convertVideo ($sFile, $sFileOut, $sExt, $aParams, $aOptions)
$sOutput = `$sCommand`;
$this->addToLog("\n---\n{$sCommand}\n{$sOutput}\n");

if (!file_exists($sFileOut) || 0 == filesize($sFileOut))
if (!file_exists($sFileOut) || 0 == filesize($sFileOut)) {
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: _convertVideo failed for file ({$sFile}):\n{$sCommand}\n{$sOutput}\n");
return false;
}

if ($bRename && !rename($sFileOut, $sFile)) // rename tmp file, if tmp file was generated
if ($bRename && !rename($sFileOut, $sFile)) { // rename tmp file, if tmp file was generated
bx_log('sys_transcoder', "[{$this->_aObject['object']}] ERROR: _convertVideo failed, final rename from {$sFileOut} to {$sFile} failed");
return false;
}

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion install/sql/system.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5369,7 +5369,8 @@ INSERT INTO `sys_objects_logs` (`object`, `module`, `logs_storage`, `title`, `ac
('sys_twilio', 'system', 'Auto', '_sys_log_twilio', 1, '', ''),
('sys_push', 'system', 'Auto', '_sys_log_push', 1, '', ''),
('sys_payments', 'system', 'Auto', '_sys_log_payments', 1, '', ''),
('sys_cron_jobs', 'system', 'Auto', '_sys_log_cron_jobs', 0, '', '');
('sys_cron_jobs', 'system', 'Auto', '_sys_log_cron_jobs', 0, '', ''),
('sys_transcoder', 'system', 'Auto', '_sys_log_transcoder', 1, '', '');


-- --------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/english/data/langs/system/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,7 @@ If it is not enabled then please consider implement this optimization, since it
<string name="_sys_log_push"><![CDATA[System: PUSH]]></string>
<string name="_sys_log_payments"><![CDATA[System: Payments]]></string>
<string name="_sys_log_cron_jobs"><![CDATA[System: Cron jobs]]></string>
<string name="_sys_log_transcoder"><![CDATA[System: Transcoder]]></string>
<string name="_sys_macros_malformed"><![CDATA[Error: malformed macros]]></string>
<string name="_sys_macros_unsafe"><![CDATA[Error: unsafe macros]]></string>
<string name="_sys_macros_output_not_displayable"><![CDATA[Error: output isn't displayable]]></string>
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/russian/data/langs/system/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,7 @@
<string name="_sys_log_push"><![CDATA[Система: PUSH]]></string>
<string name="_sys_log_payments"><![CDATA[Система: Платежи]]></string>
<string name="_sys_log_cron_jobs"><![CDATA[System: Задания Cron]]></string>
<string name="_sys_log_transcoder"><![CDATA[System: Транскодер]]></string>
<string name="_sys_macros_malformed"><![CDATA[Ошибка: некорректный макрос]]></string>
<string name="_sys_macros_unsafe"><![CDATA[Ошибка: небезопасный макрос]]></string>
<string name="_sys_macros_output_not_displayable"><![CDATA[Ошибка: некорректный вывод макроса]]></string>
Expand Down

0 comments on commit 6e4f8ff

Please sign in to comment.