/** * @action notify * @disableTags TAG_WIDGET_SESSION,TAG_ENTITLEMENT_ENTRY,TAG_ENTITLEMENT_CATEGORY * @param int $id integration job id */ public function notifyAction($id) { $coreType = IntegrationPlugin::getBatchJobTypeCoreValue(IntegrationBatchJobType::INTEGRATION); $batchJob = BatchJobPeer::retrieveByPK($id); $invalidJobId = false; $invalidKs = false; if (!self::validateKs($batchJob)) { $invalidKs = true; KalturaLog::err("ks not valid for notifying job [{$id}]"); } elseif (!$batchJob) { $invalidJobId = true; KalturaLog::err("Job [{$id}] not found"); } elseif ($batchJob->getJobType() != $coreType) { $invalidJobId = true; KalturaLog::err("Job [{$id}] wrong type [" . $batchJob->getJobType() . "] expected [" . $coreType . "]"); } elseif ($batchJob->getStatus() != KalturaBatchJobStatus::ALMOST_DONE) { $invalidJobId = true; KalturaLog::err("Job [{$id}] wrong status [" . $batchJob->getStatus() . "] expected [" . KalturaBatchJobStatus::ALMOST_DONE . "]"); } elseif ($batchJob->getPartnerId() != kCurrentContext::getCurrentPartnerId()) { $invalidKs = true; KalturaLog::err("Job [{$id}] of wrong partner [" . $batchJob->getPartnerId() . "] expected [" . kCurrentContext::getCurrentPartnerId() . "]"); } if ($invalidJobId) { throw new KalturaAPIException(KalturaErrors::INVALID_BATCHJOB_ID, $id); } if ($invalidKs) { throw new KalturaAPIException(KalturaIntegrationErrors::INTEGRATION_NOTIFY_FAILED); } kJobsManager::updateBatchJob($batchJob, KalturaBatchJobStatus::FINISHED); }
/** * Will investigate a single entry */ public function execute() { $this->forceSystemAuthentication(); $batchjob_id = @$_REQUEST["batchjob_id"]; $entry_id = @$_REQUEST["entry_id"]; $job = BatchJobPeer::retrieveByPK($batchjob_id); if ($job) { $job->setStatus(BatchJob::BATCHJOB_STATUS_PENDING); $job->save(); } $this->redirect("/system/investigate?entry_id={$entry_id}"); }
/** * batch updateExclusiveFileSyncImportJob action updates a BatchJob of type FILESYNC_IMPORT that was claimed using the getExclusiveFileSyncImportJobs * * @action updateExclusiveFileSyncImportJob * @param int $id The id of the job to free * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param KalturaBatchJob $job * @return KalturaBatchJob */ function updateExclusiveFileSyncImportJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job) { $dbBatchJob = BatchJobPeer::retrieveByPK($id); // verifies that the job is of the right type if ($dbBatchJob->getJobType() != KalturaBatchJobType::FILESYNC_IMPORT) { throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job)); } $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob)); $batchJob = new KalturaBatchJob(); // start from blank return $batchJob->fromObject($dbBatchJob); }
/** * batch updateExclusiveVirusScanJob action updates a BatchJob of type VIRUS_SCAN that was claimed using the getExclusiveVirusScanJobs * * @action updateExclusiveVirusScanJob * @param int $id The id of the job to free * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param KalturaBatchJob $job * @return KalturaBatchJob */ function updateExclusiveVirusScanJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job) { $dbBatchJob = BatchJobPeer::retrieveByPK($id); // verifies that the job is of the right type $jobType = VirusScanPlugin::getBatchJobTypeCoreValue(VirusScanBatchJobType::VIRUS_SCAN); if ($dbBatchJob->getJobType() != $jobType) { throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job)); } $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob)); $batchJob = new KalturaBatchJob(); // start from blank return $batchJob->fromObject($dbBatchJob); }
/** * * @param int $objectType * @param string $objectId * @return ISyncableFile */ public static function retrieveObject($objectType, $objectId) { $object = null; switch ($objectType) { case FileSyncObjectType::ENTRY: entryPeer::setUseCriteriaFilter(false); $object = entryPeer::retrieveByPK($objectId); entryPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::UICONF: uiConfPeer::setUseCriteriaFilter(false); $object = uiConfPeer::retrieveByPK($objectId); uiConfPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::BATCHJOB: BatchJobPeer::setUseCriteriaFilter(false); $object = BatchJobPeer::retrieveByPK($objectId); BatchJobPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::FLAVOR_ASSET: assetPeer::setUseCriteriaFilter(false); $object = assetPeer::retrieveById($objectId); assetPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::SYNDICATION_FEED: syndicationFeedPeer::setUseCriteriaFilter(false); $object = syndicationFeedPeer::retrieveByPK($objectId); syndicationFeedPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::CONVERSION_PROFILE: conversionProfile2Peer::setUseCriteriaFilter(false); $object = conversionProfile2Peer::retrieveByPK($objectId); conversionProfile2Peer::setUseCriteriaFilter(true); break; case FileSyncObjectType::FILE_ASSET: conversionProfile2Peer::setUseCriteriaFilter(false); $object = FileAssetPeer::retrieveByPK($objectId); conversionProfile2Peer::setUseCriteriaFilter(true); break; } if ($object == null) { $object = KalturaPluginManager::loadObject('ISyncableFile', $objectType, array('objectId' => $objectId)); } if ($object == null) { $error = __METHOD__ . " Cannot find object type [" . $objectType . "] with object_id [" . $objectId . "]"; KalturaLog::err($error); throw new kFileSyncException($error); } return $object; }
public function getEntryId(FileSync $fileSync) { if ($fileSync->getObjectType() == FileSyncObjectType::ENTRY) { return $fileSync->getObjectId(); } if ($fileSync->getObjectType() == FileSyncObjectType::BATCHJOB) { $job = BatchJobPeer::retrieveByPK($fileSync->getObjectId()); if ($job) { return $job->getEntryId(); } } if ($fileSync->getObjectType() == FileSyncObjectType::FLAVOR_ASSET) { $flavor = flavorAssetPeer::retrieveById($fileSync->getObjectId()); if ($flavor) { return $flavor->getEntryId(); } } return null; }
/** * @action notify * @disableTags TAG_WIDGET_SESSION,TAG_ENTITLEMENT_ENTRY,TAG_ENTITLEMENT_CATEGORY * @param int $id integration job id */ public function notifyAction($id) { $coreType = IntegrationPlugin::getBatchJobTypeCoreValue(IntegrationBatchJobType::INTEGRATION); $batchJob = BatchJobPeer::retrieveByPK($id); $invalid = false; if (!$batchJob) { $invalid = true; KalturaLog::err("Job [{$id}] not found"); } elseif ($batchJob->getJobType() != $coreType) { $invalid = true; KalturaLog::err("Job [{$id}] wrong type [" . $batchJob->getJobType() . "] expected [" . $coreType . "]"); } elseif ($batchJob->getStatus() != KalturaBatchJobStatus::ALMOST_DONE) { $invalid = true; KalturaLog::err("Job [{$id}] wrong status [" . $batchJob->getStatus() . "] expected [" . KalturaBatchJobStatus::ALMOST_DONE . "]"); } if ($invalid) { throw new KalturaAPIException(KalturaErrors::INVALID_BATCHJOB_ID, $id); } kJobsManager::updateBatchJob($batchJob, KalturaBatchJobStatus::FINISHED); }
/** * @action notify * @disableTags TAG_WIDGET_SESSION,TAG_ENTITLEMENT_ENTRY,TAG_ENTITLEMENT_CATEGORY * @param int $id distribution job id */ public function notifyAction($id) { $submitCoreType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_SUBMIT); $updateCoreType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_UPDATE); $deleteCoreType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_DELETE); $validJobTypes = array($submitCoreType, $updateCoreType, $deleteCoreType); $batchJob = BatchJobPeer::retrieveByPK($id); $invalid = false; if (!$batchJob) { $invalid = true; KalturaLog::err("Job [{$id}] not found"); } elseif (!in_array($batchJob->getJobType(), $validJobTypes)) { $invalid = true; KalturaLog::err("Job [{$id}] wrong type [" . $batchJob->getJobType() . "] expected [" . implode(', ', $validJobTypes) . "]"); } elseif ($batchJob->getJobSubType() != UnicornDistributionProvider::get()->getType()) { $invalid = true; KalturaLog::err("Job [{$id}] wrong sub-type [" . $batchJob->getJobSubType() . "] expected [" . UnicornDistributionProvider::get()->getType() . "]"); } elseif ($batchJob->getStatus() != KalturaBatchJobStatus::ALMOST_DONE) { $invalid = true; KalturaLog::err("Job [{$id}] wrong status [" . $batchJob->getStatus() . "] expected [" . KalturaBatchJobStatus::ALMOST_DONE . "]"); } if ($invalid) { throw new KalturaAPIException(KalturaErrors::INVALID_BATCHJOB_ID, $id); } kJobsManager::updateBatchJob($batchJob, KalturaBatchJobStatus::FINISHED); $data = $batchJob->getData(); /* @var $data kDistributionJobData */ $providerData = $data->getProviderData(); /* @var $providerData kUnicornDistributionJobProviderData */ $entryDistribution = EntryDistributionPeer::retrieveByPK($data->getEntryDistributionId()); if ($entryDistribution) { $entryDistribution->putInCustomData(kUnicornDistributionJobProviderData::CUSTOM_DATA_FLAVOR_ASSET_OLD_VERSION, $providerData->getFlavorAssetVersion()); $entryDistribution->save(); } if ($batchJob->getJobType() == $submitCoreType) { $this->attachRemoteAssetResource($batchJob->getEntry(), $batchJob->getData()); } if ($batchJob->getJobType() == $deleteCoreType) { $this->detachRemoteAssetResource($batchJob->getEntry(), $batchJob->getData()); } }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $job_type = $this->getPM("job_type"); $processor_name = $this->getPM("processor_name"); $processor_timeout = $this->getPM("processor_timeout"); $over_quota_partners = $this->getPM("over_quota_partners"); $defered_partners = $this->getPM("defered_partners"); $con = Propel::getConnection(); // fetch one pending row of a given job_type // where the over_quota_partner requests are dropped // and defered_partners request are of less priority $query = "SELECT " . BatchJobPeer::ID . " FROM " . BatchJobPeer::TABLE_NAME . " WHERE " . BatchJobPeer::STATUS . "=" . BatchJob::BATCHJOB_STATUS_PENDING . " AND " . BatchJobPeer::JOB_TYPE . "=" . $job_type . " " . (count($over_quota_partners) ? " AND " . BatchJobPeer::PARTNER_ID . " NOT IN ({$over_quota_partners}) " : "") . " ORDER BY " . (count($defered_partners) ? BatchJobPeer::PARTNER_ID . " IN ({$defered_partners}), " : "") . BatchJobPeer::CREATED_AT . " LIMIT 1"; $statement = $con->prepareStatement($query); $resultset = $statement->executeQuery(); $batch_job = null; while ($resultset->next()) { $batch_job = BatchJobPeer::retrieveByPK($resultset->getInt('ID')); } $batch_job = BatchJobPeer::doSelectOne($c); if ($batch_job) { // force update to work on the currently selected row and ensure it is still in pending status $c->add(BatchJobPeer::ID, $batch_job->getId()); $c->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_PENDING); $update = new Criteria(); $update->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_QUEUED); $update->add(BatchJobPeer::PROCESSOR_NAME, $processor_name); $update->add(BatchJobPeer::PROCESSOR_EXPIRATION, time() + $processor_timeout); $affectedRows = BasePeer::doUpdate($c, $update, $con); if ($affectedRows != 1) { $batch_job = null; } } if (!$batch_job) { //xx$this->addError ( APIErrors::INVALID_ENTRY_ID, $this->getObjectPrefix() , $entry_id ); } else { $wrapper = objectWrapperBase::getWrapperClass($batch_job, objectWrapperBase::DETAIL_LEVEL_REGULAR); // TODO - remove this code when cache works properly when saving objects (in their save method) $wrapper->removeFromCache("batch_job", $batch_job->getId()); $this->addMsg("batchjob", $wrapper); } }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $prefix = $this->getObjectPrefix(); $batchjob_id = $this->getPM("{$prefix}_id"); $batchjob = BatchJobPeer::retrieveByPK($batchjob_id); if (!$batchjob) { $this->addError(APIErrors::INVALID_BATCHJOB_ID, $batchjob_id); return; } // get the new properties for the batchjob from the request $batchjob_update_data = new BatchJob(); $obj_wrapper = objectWrapperBase::getWrapperClass($batchjob_update_data, 0); $fields_modified = baseObjectUtils::fillObjectFromMap($this->getInputParams(), $batchjob_update_data, "{$prefix}_", $obj_wrapper->getUpdateableFields()); if (count($fields_modified) > 0) { if ($batchjob_update_data) { baseObjectUtils::fillObjectFromObject($obj_wrapper->getUpdateableFields(), $batchjob_update_data, $batchjob, baseObjectUtils::CLONE_POLICY_PREFER_NEW, null, BasePeer::TYPE_PHPNAME); } $batchjob->save(); } $wrapper = objectWrapperBase::getWrapperClass($batchjob, objectWrapperBase::DETAIL_LEVEL_REGULAR); $wrapper->removeFromCache("batchjob", $batchjob->getId()); $this->addMsg("{$prefix}", $wrapper); $this->addDebug("modified_fields", $fields_modified); }
/** * @return BatchJob */ public function getRootJob() { if ($this->aRootJob == null && $this->getRootJobId()) { $this->aRootJob = BatchJobPeer::retrieveByPK($this->getRootJobId()); } return $this->aRootJob; }
/** * batch updateExclusiveJobAction action updates a BatchJob of extended type that was claimed using the getExclusiveJobs * * @action updateExclusiveJob * @param int $id The id of the job to free * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param KalturaBatchJob $job * @return KalturaBatchJob */ function updateExclusiveJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job) { $dbBatchJob = BatchJobPeer::retrieveByPK($id); $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob)); $batchJob = new KalturaBatchJob(); // start from blank return $batchJob->fromObject($dbBatchJob); }
/** * * @param $id * @param kExclusiveLockKey db_lock_object * @param db_lock_objectstatus - optional. will be used to set the status once the object is free * @return BatchJob */ public static function freeExclusive($id, kExclusiveLockKey $lockKey, $resetExecutionAttempts = false) { $c = new Criteria(); $c->add(BatchJobLockPeer::ID, $id); $c->add(BatchJobLockPeer::SCHEDULER_ID, $lockKey->getSchedulerId()); $c->add(BatchJobLockPeer::WORKER_ID, $lockKey->getWorkerId()); $c->add(BatchJobLockPeer::BATCH_INDEX, $lockKey->getBatchIndex()); $db_lock_object = BatchJobLockPeer::doSelectOne($c); if (!$db_lock_object) { if (BatchJobLockPeer::retrieveByPK($id)) { throw new APIException(APIErrors::FREE_EXCLUSIVE_JOB_FAILED, $id, $lockKey->getSchedulerId(), $lockKey->getWorkerId(), $lockKey->getBatchIndex()); } else { return BatchJobPeer::retrieveByPK($id); } } $db_object = $db_lock_object->getBatchJob(); if ($resetExecutionAttempts || in_array($db_lock_object->getStatus(), BatchJobPeer::getClosedStatusList())) { $db_lock_object->setExecutionAttempts(0); } $db_lock_object->setSchedulerId(null); $db_lock_object->setWorkerId(null); $db_lock_object->setBatchIndex(null); $db_lock_object->setExpiration(null); $db_lock_object->save(); if ($db_object->getStatus() != BatchJob::BATCHJOB_STATUS_ABORTED && $db_object->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) { $db_object = kJobsManager::abortDbBatchJob($db_object); } return $db_object; }
private function updateJob(KalturaBatchJob $job) { $dbJob = BatchJobPeer::retrieveByPK($job->id); $dbJob = $job->toObject($dbJob); $dbJob->save(); }
/** * batch getStatusAction returns the status of task * * @action getStatus * @param int $jobId the id of the job * @param KalturaBatchJobType $jobType the type of the job * @param KalturaFilterPager $pager pager for the child jobs * @return KalturaBatchJobResponse */ function getStatusAction($jobId, $jobType, KalturaFilterPager $pager = null) { $dbJobType = kPluginableEnumsManager::apiToCore('BatchJobType', $jobType); $dbBatchJob = BatchJobPeer::retrieveByPK($jobId); if ($dbBatchJob->getJobType() != $dbJobType) { throw new KalturaAPIException(APIErrors::GET_EXCLUSIVE_JOB_WRONG_TYPE, $jobType, $dbBatchJob->getId()); } $job = new KalturaBatchJob(); $job->fromObject($dbBatchJob); $batchJobResponse = new KalturaBatchJobResponse(); $batchJobResponse->batchJob = $job; if (!$pager) { $pager = new KalturaFilterPager(); } $c = new Criteria(); $pager->attachToCriteria($c); $childBatchJobs = $dbBatchJob->getChildJobs($c); $batchJobResponse->childBatchJobs = KalturaBatchJobArray::fromBatchJobArray($childBatchJobs); return $batchJobResponse; }
public function objectDeleted(BaseObject $object, BatchJob $raisedJob = null) { /* @var $object FileSync */ $syncKey = kFileSyncUtils::getKeyForFileSync($object); $entryId = null; switch ($object->getObjectType()) { case FileSyncObjectType::ENTRY: $entryId = $object->getObjectId(); break; case FileSyncObjectType::BATCHJOB: BatchJobPeer::setUseCriteriaFilter(false); $batchJob = BatchJobPeer::retrieveByPK($object->getObjectId()); if ($batchJob) { $entryId = $batchJob->getEntryId(); } BatchJobPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::ASSET: assetPeer::setUseCriteriaFilter(false); $asset = assetPeer::retrieveById($object->getId()); if ($asset) { $entryId = $asset->getEntryId(); //the next piece of code checks whether the entry to which //the deleted asset belongs to is a "replacement" entry $entry = entryPeer::retrieveByPKNoFilter($entryId); if (!$entry) { KalturaLog::alert("No entry found by the ID of [{$entryId}]"); } else { if ($entry->getReplacedEntryId()) { KalturaLog::info("Will not handle event - deleted asset belongs to replacement entry"); return; } } } assetPeer::setUseCriteriaFilter(true); break; } $storage = StorageProfilePeer::retrieveByPK($object->getDc()); kJobsManager::addStorageDeleteJob($raisedJob, $entryId, $storage, $object); }
/** * @param int $jobId * @param int $jobType * @param bool $force - forces retry even if the job is locked. * @return BatchJob */ public static function retryJob($jobId, $jobType, $force = false) { $dbBatchJob = BatchJobPeer::retrieveByPK($jobId); if ($dbBatchJob->getJobType() != $jobType) { throw new APIException(APIErrors::GET_EXCLUSIVE_JOB_WRONG_TYPE, $jobType, $dbBatchJob->getId()); } $dbBatchJob->setExecutionStatus(BatchJobExecutionStatus::NORMAL); // if not currently locked $dbBatchJobLock = $dbBatchJob->getBatchJobLock(); if ($dbBatchJobLock === null) { // retry of non locked entry $dbBatchJob = self::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_RETRY); } elseif ($force) { // retry of scheduled entry $dbBatchJobLock->setExecutionAttempts(0); $dbBatchJobLock->setStatus(BatchJob::BATCHJOB_STATUS_RETRY); $dbBatchJobLock->setExpiration(time() + BatchJobLockPeer::getRetryInterval($jobType)); $dbBatchJob->setStatus(BatchJob::BATCHJOB_STATUS_RETRY); $dbBatchJob->save(); } return $dbBatchJob; }
/** * * * @action getDryRunResults * @param int $requestId * @return KalturaObjectListResponse * * @throws KalturaScheduledTaskErrors::SCHEDULED_TASK_PROFILE_NOT_FOUND */ public function getDryRunResultsAction($requestId) { $this->applyPartnerFilterForClass('BatchJob'); $batchJob = BatchJobPeer::retrieveByPK($requestId); $batchJobType = ScheduledTaskPlugin::getBatchJobTypeCoreValue(ScheduledTaskBatchType::SCHEDULED_TASK); if (is_null($batchJob) || $batchJob->getJobType() != $batchJobType) { throw new KalturaAPIException(KalturaScheduledTaskErrors::OBJECT_NOT_FOUND); } if (in_array($batchJob->getStatus(), array(KalturaBatchJobStatus::FAILED, KalturaBatchJobStatus::FATAL))) { throw new KalturaAPIException(KalturaScheduledTaskErrors::DRY_RUN_FAILED); } if ($batchJob->getStatus() != KalturaBatchJobStatus::FINISHED) { throw new KalturaAPIException(KalturaScheduledTaskErrors::DRY_RUN_NOT_READY); } $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD); $data = kFileSyncUtils::file_get_contents($syncKey, true); $results = unserialize($data); return $results; }
public function objectChanged(BaseObject $object, array $modifiedColumns) { if ($object instanceof entry && in_array(entryPeer::STATUS, $modifiedColumns) && ($object->getStatus() == entryStatus::READY || $object->getStatus() == entryStatus::ERROR_CONVERTING) && $object->getReplacedEntryId()) { kFlowHelper::handleEntryReplacement($object); return true; } if ($object instanceof UploadToken && in_array(UploadTokenPeer::STATUS, $modifiedColumns) && $object->getStatus() == UploadToken::UPLOAD_TOKEN_FULL_UPLOAD) { kFlowHelper::handleUploadFinished($object); return true; } if ($object instanceof BatchJob && $object->getJobType() == BatchJobType::BULKUPLOAD && $object->getStatus() == BatchJob::BATCHJOB_STATUS_ABORTED && in_array(BatchJobPeer::STATUS, $modifiedColumns) && in_array($object->getColumnsOldValue(BatchJobPeer::STATUS), BatchJobPeer::getClosedStatusList())) { $partner = $object->getPartner(); if ($partner->getEnableBulkUploadNotificationsEmails()) { kFlowHelper::sendBulkUploadNotificationEmail($object, MailType::MAIL_TYPE_BULKUPLOAD_ABORTED, array($partner->getAdminName(), $object->getId(), kFlowHelper::createBulkUploadLogUrl($object))); } return true; } if ($object instanceof UserRole && in_array(UserRolePeer::PERMISSION_NAMES, $modifiedColumns)) { $filter = new kuserFilter(); $filter->set('_eq_role_ids', $object->getId()); kJobsManager::addIndexJob($object->getPartnerId(), IndexObjectType::USER, $filter, false); return true; } if ($object instanceof FileSync) { $c = new Criteria(); $c->add(BatchJobLockPeer::OBJECT_ID, $object->getId()); $c->add(BatchJobLockPeer::OBJECT_TYPE, BatchJobObjectType::FILE_SYNC); $c->add(BatchJobLockPeer::JOB_TYPE, BatchJobType::FILESYNC_IMPORT); $c->add(BatchJobLockPeer::STATUS, array(BatchJob::BATCHJOB_STATUS_RETRY, BatchJob::BATCHJOB_STATUS_PENDING), Criteria::IN); $fileSyncImportJobs = BatchJobLockPeer::doSelect($c); foreach ($fileSyncImportJobs as $fileSyncImportJob) { kJobsManager::abortDbBatchJob(BatchJobPeer::retrieveByPK($fileSyncImportJob->getId())); } return true; } if (!$object instanceof flavorAsset || !in_array(assetPeer::STATUS, $modifiedColumns)) { return true; } $entry = entryPeer::retrieveByPKNoFilter($object->getEntryId()); KalturaLog::info("Asset id [" . $object->getId() . "] isOriginal [" . $object->getIsOriginal() . "] status [" . $object->getStatus() . "]"); if ($object->getIsOriginal()) { return true; } if ($object->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING) { $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR; $offset = $entry->getThumbOffset(); // entry getThumbOffset now takes the partner DefThumbOffset into consideration $syncKey = $object->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey, false); if (!$fileSync) { return true; } $srcFileSyncLocalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey); if ($srcFileSyncLocalPath) { kJobsManager::addPostConvertJob(null, $postConvertAssetType, $srcFileSyncLocalPath, $object->getId(), null, $entry->getCreateThumb(), $offset); } } elseif ($object->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { // If we get a ready flavor and the entry is in no content if ($entry->getStatus() == entryStatus::NO_CONTENT) { $entry->setStatus(entryStatus::PENDING); // we change the entry to pending $entry->save(); } } return true; }
/** * @param int $jobId * @param int $jobType * @param bool $force - forces retry even if the job is locked. * @return BatchJob */ public static function retryJob($jobId, $jobType, $force = false) { $dbBatchJob = BatchJobPeer::retrieveByPK($jobId); if ($dbBatchJob->getJobType() != $jobType) { throw new APIException(APIErrors::GET_EXCLUSIVE_JOB_WRONG_TYPE, $jobType, $dbBatchJob->getId()); } $dbBatchJob->setAbort(false); // if not currently locked if (!$dbBatchJob->getSchedulerId()) { $dbBatchJob->setExecutionAttempts(0); $dbBatchJob = self::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_RETRY); } elseif ($force) { $dbBatchJob->setExecutionAttempts(0); $dbBatchJob->setStatus(BatchJob::BATCHJOB_STATUS_RETRY); $dbBatchJob->setStatus(BatchJob::BATCHJOB_STATUS_RETRY); $dbBatchJob->setCheckAgainTimeout(time() + BatchJobPeer::getCheckAgainTimeout($jobType)); $dbBatchJob->save(); } return $dbBatchJob; }
/** * Do converting * @param KalturaConvertJobData $data Job data * @return array Result of converting */ public function convertJob(KalturaConvertJobData &$data) { $outputParams = $data->flavorParamsOutput; $videoCodec = $outputParams->videoCodec; $videoBitrate = $outputParams->videoBitrate; $width = $outputParams->width; $height = $outputParams->height; $presetName = $outputParams->name; $preset = array(); $preset[kWAMS::CONVERT_PARAM_PRESET_NAME] = $outputParams->name; $preset[kWAMS::CONVERT_PARAM_AUDIO_CODEC] = $outputParams->audioCodec; $preset[kWAMS::CONVERT_PARAM_AUDIO_BITRATE] = $outputParams->audioBitrate; $preset[kWAMS::CONVERT_PARAM_AUDIO_CHANNELS] = $outputParams->audioChannels; $preset[kWAMS::CONVERT_PARAM_AUDIO_SAMPLE_RATE] = $outputParams->audioSampleRate; $preset[kWAMS::CONVERT_PARAM_VIDEO_CODEC] = $outputParams->videoCodec; $preset[kWAMS::CONVERT_PARAM_VIDEO_WIDTH] = $outputParams->width; $preset[kWAMS::CONVERT_PARAM_VIDEO_HEIGHT] = $outputParams->height; $preset[kWAMS::CONVERT_PARAM_VIDEO_BITRATE] = $outputParams->videoBitrate; KalturaLog::debug("Video params output: preset = [{$presetName}], videoCodec = [{$videoCodec}], videoBitrate = [{$videoBitrate}], width = [{$width}], height = [{$height}]"); $start = microtime(true); $kWAMS = kWAMS::getInstance($data->flavorParamsOutput->partnerId); $wamsJobId = $kWAMS->addConvertJob($data->srcFileSyncWamsAssetId, $preset); Propel::disableInstancePooling(); while ($kWAMS->isJobProcessing($wamsJobId)) { // check Kaltura Batch Job Status if (BatchJobPeer::retrieveByPK($this->batchJobId)->getAbort()) { $kWAMS->cancelJob($wamsJobId); } sleep(5); } Propel::enableInstancePooling(); $data->destFileSyncWamsAssetId = $kWAMS->getOutputAssetId($wamsJobId); $end = microtime(true); $duration = $end - $start; KalturaLog::info($this->getName() . ": took [{$duration}] seconds"); return array(true, null); }
private function addWamsFile(KalturaBatchJob $job, KalturaConvertJobData $data) { KalturaLog::debug("wams file({$job->id}, {$data->destFileSyncWamsAssetId})"); if (empty($data->destFileSyncWamsAssetId)) { KalturaLog::err("Error: add wams file failed"); die; } else { Propel::disableInstancePooling(); if (BatchJobPeer::retrieveByPK($job->id)->getAbort()) { kWAMS::getInstance($job->partnerId)->deleteAssetById($data->destFileSyncWamsAssetId); return $job; } Propel::enableInstancePooling(); $job->status = KalturaBatchJobStatus::FINISHED; $job->message = "File ready in WAMS"; return $this->closeJob($job, null, null, $job->message, $job->status, $data); } }
/** * batch updateExclusiveDistributionFetchReportJob action updates a BatchJob of type DISTRIBUTION_FETCH_REPORT that was claimed using the getExclusiveDistributionFetchReportJobs * * @action updateExclusiveDistributionFetchReportJob * @param int $id The id of the job to free * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param KalturaBatchJob $job * @return KalturaBatchJob */ function updateExclusiveDistributionFetchReportJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job) { $dbBatchJob = BatchJobPeer::retrieveByPK($id); // verifies that the job is of the right type $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_FETCH_REPORT); if ($dbBatchJob->getJobType() != $jobType) { throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job)); } $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob)); $batchJob = new KalturaBatchJob(); // start from blank return $batchJob->fromObject($dbBatchJob); }
/** * @param BaseObject $object */ protected function setRelatedObject(AuditTrail $auditTrail, BaseObject $object) { if (class_exists('Metadata') && $object instanceof Metadata) { $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA_PROFILE); $auditTrail->setRelatedObjectId($object->getMetadataProfileId()); } if ($auditTrail->getAction() == AuditTrail::AUDIT_TRAIL_ACTION_FILE_SYNC_CREATED) { $peer = $object->getPeer(); $objectType = $peer->getOMClass(false, null); $auditTrail->setRelatedObjectType($objectType); $auditTrail->setRelatedObjectId($object->getId()); } if ($object instanceof FileSync) { switch ($object->getObjectType()) { case FileSyncObjectType::ENTRY: $auditTrail->setRelatedObjectType(AuditTrailObjectType::ENTRY); $auditTrail->setRelatedObjectId($object->getObjectId()); $auditTrail->setEntryId($object->getObjectId()); break; case FileSyncObjectType::UICONF: $auditTrail->setRelatedObjectType(AuditTrailObjectType::UI_CONF); $auditTrail->setRelatedObjectId($object->getObjectId()); break; case FileSyncObjectType::BATCHJOB: $auditTrail->setRelatedObjectType(AuditTrailObjectType::BATCH_JOB); $auditTrail->setRelatedObjectId($object->getObjectId()); $batchJob = BatchJobPeer::retrieveByPK($object->getObjectId()); if ($batchJob) { $auditTrail->setEntryId($batchJob->getEntryId()); } break; case FileSyncObjectType::FLAVOR_ASSET: $auditTrail->setRelatedObjectType(AuditTrailObjectType::FLAVOR_ASSET); $auditTrail->setRelatedObjectId($object->getObjectId()); $flavorAsset = assetPeer::retrieveById($object->getObjectId()); if ($flavorAsset) { $auditTrail->setEntryId($flavorAsset->getEntryId()); } break; case FileSyncObjectType::METADATA: $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA); $auditTrail->setRelatedObjectId($object->getObjectId()); if (class_exists('Metadata')) { $metadata = MetadataPeer::retrieveByPK($object->getObjectId()); if ($metadata && $metadata->getObjectType() == MetadataObjectType::ENTRY) { $auditTrail->setEntryId($metadata->getObjectId()); } } break; case FileSyncObjectType::METADATA_PROFILE: $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA_PROFILE); $auditTrail->setRelatedObjectId($object->getObjectId()); break; } } }