Skip to content

Commit

Permalink
Now the encoder will retry 3 times in case the video fail to encode
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel authored and daniel committed Apr 24, 2019
1 parent 1f7af62 commit 9e39e04
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions objects/Encoder.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ static function getFromFileURI($fileURI) {
return false;
}

static function run() {
static function run($try = 0) {
$try++;
$obj = new stdClass();
$obj->error = true;
// check if is encoding something
Expand All @@ -514,10 +515,19 @@ static function run() {
$encoder->save();
$objFile = static::downloadFile($encoder->getId());
if ($objFile->error) {
$obj->msg = $objFile->msg;
$encoder->setStatus("error");
$encoder->setStatus_obs("Could not download the file ");
$encoder->save();
if ($try < 4) {
$msg = "Trying again: [$try] => Could not download the file ";
error_log($msg);
$encoder->setStatus("queue");
$encoder->setStatus_obs($msg);
$encoder->save();
self::run($try);
} else {
$obj->msg = $objFile->msg;
$encoder->setStatus("error");
$encoder->setStatus_obs("Could not download the file ");
$encoder->save();
}
} else {
$encoder->setStatus("encoding");
$encoder->save();
Expand All @@ -527,11 +537,20 @@ static function run() {
$code = new Format($encoder->getFormats_id());
$resp = $code->run($objFile->pathFileName, $encoder->getId());
if ($resp->error) {
$obj->msg = "Execute code error " . json_encode($resp->msg) . " \n Code: {$resp->code}";
error_log("Encoder Run: " . json_encode($obj));
$encoder->setStatus("error");
$encoder->setStatus_obs($obj->msg);
$encoder->save();
if ($try < 4) {
$msg = "Trying again: [$try] => Execute code error " . json_encode($resp->msg) . " \n Code: {$resp->code}";
error_log($msg);
$encoder->setStatus("queue");
$encoder->setStatus_obs($msg);
$encoder->save();
self::run($try);
} else {
$obj->msg = "Execute code error " . json_encode($resp->msg) . " \n Code: {$resp->code}";
error_log("Encoder Run: " . json_encode($obj));
$encoder->setStatus("error");
$encoder->setStatus_obs($obj->msg);
$encoder->save();
}
} else {
$obj->error = false;
$obj->msg = $resp->code;
Expand Down Expand Up @@ -671,10 +690,10 @@ function send() {
}
} else {
$extension = $f->getExtension();
if($formatId==29){ // if it is HLS send the compacted file
if ($formatId == 29) { // if it is HLS send the compacted file
$extension = "zip";
}

$file = $global['systemRootPath'] . "videos/{$this->id}_tmpFile_converted.{$extension}";
$r = static::sendFile($file, $videos_id, $extension, $this);
if ($r->error) {
Expand Down

0 comments on commit 9e39e04

Please sign in to comment.