public static function decideProfileFlavorsConvert(BatchJob $parentJob, BatchJob $convertProfileJob, array $flavors, array $conversionProfileFlavorParams, mediaInfo $mediaInfo = null) { $entryId = $convertProfileJob->getEntryId(); $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId); if (is_null($originalFlavorAsset)) { $errDescription = 'Original flavor asset not found'; KalturaLog::err($errDescription); $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE); kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING); return false; } $errDescription = null; $finalFlavors = self::validateConversionProfile($convertProfileJob->getPartnerId(), $entryId, $mediaInfo, $flavors, $conversionProfileFlavorParams, $errDescription); KalturaLog::log(count($finalFlavors) . " flavors returned from the decision layer"); if (is_null($finalFlavors)) { $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription); KalturaLog::log("No flavors created"); throw new Exception($errDescription); } if (strlen($errDescription)) { $err = $convertProfileJob->getDescription() . $errDescription; $convertProfileJob->setDescription($err); $convertProfileJob->save(); } $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $conversionsCreated = 0; $entry = $convertProfileJob->getEntry(); if (!$entry) { throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId); } $flavorsCollections = array(); // create a convert job per each flavor foreach ($finalFlavors as $flavor) { $flavorAsset = kBatchManager::createFlavorAsset($flavor, $entry->getPartnerId(), $entry->getId()); if (!$flavorAsset) { KalturaLog::log("Flavor asset could not be created, flavor conversion won't be created"); continue; } $collectionTag = $flavor->getCollectionTag(); if ($collectionTag) { $flavorsCollections[$collectionTag][] = $flavor; continue; } KalturaLog::log("Adding flavor conversion with flavor params output id [" . $flavor->getId() . "] and flavor params asset id [" . $flavorAsset->getId() . "]"); $madiaInfoId = $mediaInfo ? $mediaInfo->getId() : null; $createdJob = kJobsManager::addFlavorConvertJob($srcSyncKey, $flavor, $flavorAsset->getId(), $madiaInfoId, $parentJob); if ($createdJob) { $conversionsCreated++; } } foreach ($flavorsCollections as $tag => $flavors) { switch ($tag) { case flavorParams::TAG_ISM: $createdJob = kJobsManager::addConvertIsmCollectionJob($tag, $srcSyncKey, $entry, $parentJob, $flavors); if ($createdJob) { $conversionsCreated++; } break; default: KalturaLog::log("Error: Invalid collection tag [{$tag}]"); break; } } if (!$conversionsCreated) { $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription); KalturaLog::log("No flavors created: {$errDescription}"); return false; } return true; }
/** * @param BatchJob $dbBatchJob * @param kPullJobData $data * @param BatchJob $twinJob * @return BatchJob */ public static function handlePullFailed(BatchJob $dbBatchJob, kPullJobData $data, BatchJob $twinJob = null) { $rootBatchJob = $dbBatchJob->getRootJob(); if ($rootBatchJob) { $rootBatchJob = kJobsManager::failBatchJob($rootBatchJob, "Pull job " . $dbBatchJob->getId() . " failed"); } return $dbBatchJob; }
private static function setError($errDescription, BatchJob $batchJob, $batchJobType, $entryId) { $batchJob = kJobsManager::failBatchJob($batchJob, $errDescription, $batchJobType); kBatchManager::updateEntry($entryId, entryStatus::ERROR_CONVERTING); KalturaLog::err($errDescription); }
public static function handleConvertFailed(BatchJob $dbBatchJob, $engineType, $flavorAssetId, $flavorParamsOutputId, $mediaInfoId) { $flavorAsset = assetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); // try to create a convert job with the next engine if (!is_null($engineType)) { $data = $dbBatchJob->getData(); if ($data instanceof kConvartableJobData) { $data->incrementOperationSet(); $dbBatchJob->setData($data); $dbBatchJob->save(); } $newDbBatchJob = kBusinessPreConvertDL::redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, $dbBatchJob, $engineType); if ($newDbBatchJob) { return true; } } // find the root job $rootBatchJob = $dbBatchJob->getRootJob(); if (!$rootBatchJob) { return false; } // the root is already failed if ($rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED || $rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FATAL) { return false; } // bulk download root job no need to handle if ($rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) { kJobsManager::failBatchJob($rootBatchJob, "Convert job " . $dbBatchJob->getId() . " failed"); return false; } if (is_null($flavorParamsOutputId)) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } $readyBehavior = $dbBatchJob->getData()->getReadyBehavior(); if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } // failing the root profile job if all child jobs failed if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) { return false; } $siblingJobs = $rootBatchJob->getChildJobs(); foreach ($siblingJobs as $siblingJob) { /* @var $siblingJob BatchJob */ // not conversion job and should be ignored if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) { continue; } $jobData = $siblingJob->getData(); if (!$jobData || !$jobData instanceof kConvertJobData && !$jobData instanceof kPostConvertJobData) { KalturaLog::err("Job id [" . $siblingJob->getId() . "] has no valid job data"); continue; } // found child flavor asset that hasn't failed, no need to fail the root job $siblingFlavorAssetId = $jobData->getFlavorAssetId(); $siblingFlavorAsset = assetPeer::retrieveById($siblingFlavorAssetId); if ($siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_ERROR && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { return false; } } // all conversions failed, should fail the root job kJobsManager::failBatchJob($rootBatchJob, "All conversions failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; }
public static function handleConvertFailed(BatchJob $dbBatchJob, $engineType, $flavorAssetId, $flavorParamsOutputId, $mediaInfoId) { $flavorAsset = assetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } /* * On Webex error, roll back the inter-src asset version in order to allow the retry to get ARF as a source, * rather than the invlaid WMV file (product of bad nbrplayer session) */ if ($dbBatchJob->getErrNumber() == BatchJobAppErrors::BLACK_OR_SILENT_CONTENT) { $prevVer = $flavorAsset->getPreviousVersion(); $currVer = $flavorAsset->getVersion(); KalturaLog::log("Webex conversion - Garbled Audio or Black frame or Silence. Rolling back asset/file-sync version - curr({$currVer}), prev({$prevVer})"); if (isset($prevVer)) { $syncKey = $flavorAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $currVer); if (isset($syncKey)) { kFileSyncUtils::deleteSyncFileForKey($syncKey, false, true); $flavorAsset->setVersion($prevVer); $flavorAsset->setPreviousVersion(null); KalturaLog::log("Webex conversion - Rolled back"); } } } $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); // try to create a convert job with the next engine if (!is_null($engineType)) { $data = $dbBatchJob->getData(); if ($data instanceof kConvartableJobData) { $data->incrementOperationSet(); $dbBatchJob->setData($data); $dbBatchJob->save(); } $newDbBatchJob = kBusinessPreConvertDL::redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, $dbBatchJob, $engineType); if ($newDbBatchJob) { return true; } } // find the root job $rootBatchJob = $dbBatchJob->getRootJob(); if (!$rootBatchJob) { return false; } // the root is already failed if ($rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED || $rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FATAL) { return false; } // bulk download root job no need to handle if ($rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) { kJobsManager::failBatchJob($rootBatchJob, "Convert job " . $dbBatchJob->getId() . " failed"); return false; } if (is_null($flavorParamsOutputId)) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } $readyBehavior = $dbBatchJob->getData()->getReadyBehavior(); if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } // failing the root profile job if all child jobs failed if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) { return false; } $siblingJobs = $rootBatchJob->getChildJobs(); foreach ($siblingJobs as $siblingJob) { /* @var $siblingJob BatchJob */ // not conversion job and should be ignored if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) { continue; } $jobData = $siblingJob->getData(); if (!$jobData || !$jobData instanceof kConvertJobData && !$jobData instanceof kPostConvertJobData) { KalturaLog::err("Job id [" . $siblingJob->getId() . "] has no valid job data"); continue; } // found child flavor asset that hasn't failed, no need to fail the root job $siblingFlavorAssetId = $jobData->getFlavorAssetId(); $siblingFlavorAsset = assetPeer::retrieveById($siblingFlavorAssetId); if ($siblingFlavorAsset && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_ERROR && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { return false; } } // all conversions failed, should fail the root job kJobsManager::failBatchJob($rootBatchJob, "All conversions failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; }