/**
  * batch getExclusiveFileSyncImportJob action allows to get a BatchJob of type FILESYNC_IMPORT
  *
  * @action getExclusiveFileSyncImportJobs
  * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism
  * @param int $maxExecutionTime The maximum time in seconds the job reguarly take. Is used for the locking mechanism when determining an unexpected termination of a batch-process.
  * @param int $numberOfJobs The maximum number of jobs to return.
  * @param KalturaBatchJobFilter $filter Set of rules to fetch only rartial list of jobs
  * @param int $maxOffset The maximum offset we accept for the distance from the best result.
  * @return KalturaBatchJobArray
  *
  * TODO remove the destFilePath from the job data and get it later using the api, then delete this method
  */
 function getExclusiveFileSyncImportJobsAction(KalturaExclusiveLockKey $lockKey, $maxExecutionTime, $numberOfJobs, KalturaBatchJobFilter $filter = null, $maxOffset = null)
 {
     $coreJobs = $this->getExclusiveJobs($lockKey, $maxExecutionTime, $numberOfJobs, $filter, BatchJobType::FILESYNC_IMPORT, $maxOffset);
     $jobs = KalturaBatchJobArray::fromBatchJobArray($coreJobs);
     if ($jobs) {
         foreach ($jobs as $index => $job) {
             $data = $job->data;
             // try to get destination path from file sync
             $fileSyncId = $data->filesyncId;
             $fileSync = FileSyncPeer::retrieveByPK($fileSyncId);
             if (!$fileSync) {
                 KalturaLog::err("Failed to load file sync [{$fileSyncId}] aborting job [{$job->id}]");
                 $dbJob = BatchJobPeer::retrieveByPK($job->id);
                 $dbJob->setMessage("Failed to load file sync [{$fileSyncId}]");
                 kJobsManager::abortDbBatchJob($dbJob);
                 unset($jobs[$index]);
                 continue;
             }
             $fileSyncRoot = $fileSync->getFileRoot();
             $fileSyncPath = $fileSync->getFilePath();
             if ($fileSyncRoot && $fileSyncPath) {
                 // destination path set on filesync
                 $dest_path = $fileSyncRoot . $fileSyncPath;
             } else {
                 // not set on filesync - get path from path manager
                 $fileSyncKey = kFileSyncUtils::getKeyForFileSync($fileSync);
                 list($file_root, $real_path) = kPathManager::getFilePathArr($fileSyncKey);
                 $dest_path = $file_root . $real_path;
                 // update filesync on database
                 $fileSync->setFileRoot($file_root);
                 $fileSync->setFilePath($real_path);
                 $fileSync->save();
             }
             // update job data with destination path if needed
             if (!$data->destFilePath) {
                 $data->destFilePath = $dest_path;
                 $job->data = $data;
                 KalturaLog::log('Updating destination path for job id [$job->id]');
                 $this->updateJob($job);
             }
             if (!is_dir(dirname($dest_path)) && !@mkdir(dirname($dest_path), 0755, true)) {
                 KalturaLog::ERR("Cannot create directory [{$dest_path}] - " . error_get_last());
             }
         }
     }
     return $jobs;
 }
 /**
  *
  * @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;
 }
 /**
  * 
  * @param $id
  * @param kExclusiveLockKey $lockKey
  * @param $pending_status - 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(BatchJobPeer::ID, $id);
     $c->add(BatchJobPeer::SCHEDULER_ID, $lockKey->getSchedulerId());
     $c->add(BatchJobPeer::WORKER_ID, $lockKey->getWorkerId());
     $c->add(BatchJobPeer::BATCH_INDEX, $lockKey->getBatchIndex());
     $db_object = BatchJobPeer::doSelectOne($c);
     if (!$db_object) {
         throw new APIException(APIErrors::FREE_EXCLUSIVE_JOB_FAILED, $id, $lockKey->getSchedulerId(), $lockKey->getWorkerId(), $lockKey->getBatchIndex());
     }
     if ($resetExecutionAttempts) {
         $db_object->setExecutionAttempts(0);
     }
     $db_object->setSchedulerId(null);
     $db_object->setWorkerId(null);
     $db_object->setBatchIndex(null);
     $db_object->setProcessorExpiration(null);
     $db_object->save();
     if ($db_object->getStatus() != BatchJob::BATCHJOB_STATUS_ABORTED && $db_object->getAbort()) {
         $db_object = kJobsManager::abortDbBatchJob($db_object);
     }
     return $db_object;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 /**
  * 
  * add DeleteStorage job for key
  * 
  * @param entry $entry
  * @param StorageProfile $profile
  * @param FileSyncKey $key
  */
 protected static function delete(entry $entry, StorageProfile $profile, FileSyncKey $key)
 {
     $externalFileSync = kFileSyncUtils::getReadyPendingExternalFileSyncForKey($key, $profile->getId());
     if (!$externalFileSync) {
         return;
     }
     $c = new Criteria();
     $c->add(BatchJobPeer::OBJECT_ID, $externalFileSync->getId());
     $c->add(BatchJobPeer::OBJECT_TYPE, BatchJobObjectType::FILE_SYNC);
     $c->add(BatchJobPeer::JOB_TYPE, BatchJobType::STORAGE_EXPORT);
     $c->add(BatchJobPeer::JOB_SUB_TYPE, $profile->getProtocol());
     $c->add(BatchJobPeer::ENTRY_ID, $entry->getId());
     $c->add(BatchJobPeer::STATUS, array(BatchJob::BATCHJOB_STATUS_RETRY, BatchJob::BATCHJOB_STATUS_PENDING), Criteria::IN);
     $exportJobs = BatchJobPeer::doSelect($c);
     if (!$exportJobs) {
         kJobsManager::addStorageDeleteJob(null, $entry->getId(), $profile, $externalFileSync);
     } else {
         foreach ($exportJobs as $exportJob) {
             kJobsManager::abortDbBatchJob($exportJob);
         }
     }
 }