/**
  * @param string $puser_id
  * @param string $entry
  * @param string $version
  * @param string $file_format
  * @return BatchJob
  */
 public static function addJob($puser_id, $entry, $version, $file_format)
 {
     $entryId = $entry->getId();
     $entryIntId = $entry->getIntId();
     $entryVersion = $version ? $version : $entry->getVersion();
     if ($entry) {
         $partner = $entry->getPartner();
         $email = $partner->getAdminEmail();
     }
     $data = json_encode(array('puserId' => $puser_id, 'entryId' => $entryId, 'entryIntId' => $entryIntId, 'entryVersion' => $entryVersion, 'fileFormat' => $file_format, 'email' => $email));
     $job = new BatchJob();
     $job->setJobType(BatchJobType::FLATTEN);
     $job->setData($data, true);
     $job->setStatus(BatchJob::BATCHJOB_STATUS_PENDING);
     $job->setCheckAgainTimeout(time() + 10);
     $job->setProgress(0);
     $job->setMessage('Queued');
     $job->setDescription('Queued, waiting to run');
     $job->setUpdatesCount(0);
     $job->setEntryId($entryId);
     $job->setPartnerId($entry->getPartnerId());
     $job->setSubpId($entry->getSubpId());
     $job->save();
     return $job;
 }
 /**
  * @param BatchJob $job
  * @param $errorDescription
  * @return BatchJob
  */
 protected function finishJobWithError(BatchJob $job, $errorDescription)
 {
     $job->setStatus(BatchJob::BATCHJOB_STATUS_FAILED);
     $job->setDescription($job->getDescription() . '\\n' . $errorDescription);
     $job->save();
     return $job;
 }
Exemple #3
0
 public static function updateBatchJob(BatchJob $batchJob, $status, BatchJob $twinJob = null)
 {
     $batchJob->setStatus($status);
     $batchJob->save();
     $event = new kBatchJobStatusEvent($batchJob, $twinJob);
     kEventsManager::raiseEvent($event);
     $batchJob->reload();
     return $batchJob;
 }
 private function reconvertEntry($entry_id, $conversion_profile_id, $job_priority)
 {
     $entry = entryPeer::retrieveByPK($entry_id);
     $this->error = "";
     if (!$entry) {
         $error = "Cannot reconvert entry [{$entry_id}]. Might be a deleted entry";
         return array($entry_id, null, null, $error);
     }
     $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id);
     if (!$flavorAsset) {
         $flavorAsset = assetPeer::retrieveReadyWebByEntryId($entry_id);
         if (!$flavorAsset) {
             $flavorAssets = assetPeer::retrieveFlavorsByEntryId($entry_id);
             if (!$flavorAssets) {
                 $error = "Cannot find good enough flavor asset to re-convert from";
                 return array($entry_id, $entry, null, $error);
             }
             $flavorAsset = $flavorAssets[0];
             // choose the first one
         }
     }
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     if (!$filePath) {
         $error = "Cannot find a fileSync for the flavorAsset [" . $flavorAsset->getId() . "]";
         return array($entry_id, $entry, null, $error);
     }
     $dbBatchJob = new BatchJob();
     $dbBatchJob->setEntryId($entry_id);
     $dbBatchJob->setPartnerId($entry->getPartnerId());
     $dbBatchJob->setStatus(BatchJob::BATCHJOB_STATUS_PENDING);
     $dbBatchJob->setDc(kDataCenterMgr::getCurrentDcId());
     //$dbBatchJob->setPriority ( $job_priority ); Not supported anymore
     $dbBatchJob->setObjectId($entry_id);
     $dbBatchJob->setObjectType(BatchJobObjectType::ENTRY);
     $dbBatchJob->setJobType(BatchJobType::CONVERT_PROFILE);
     $dbBatchJob->save();
     // creates a convert profile job
     $convertProfileData = new kConvertProfileJobData();
     $convertProfileData->setFlavorAssetId($flavorAsset->getId());
     $convertProfileData->setInputFileSyncLocalPath($filePath);
     kJobsManager::addJob($dbBatchJob, $convertProfileData, BatchJobType::CONVERT_PROFILE);
     // save again afget the addJob
     $dbBatchJob->save();
     return array($entry_id, $entry, $dbBatchJob, $error);
 }
 public static function addintegrationJob($objectType, $objectId, kIntegrationJobData $data)
 {
     $partnerId = kCurrentContext::getCurrentPartnerId();
     $batchJob = new BatchJob();
     $batchJob->setPartnerId($partnerId);
     $batchJob->setObjectType($objectType);
     $batchJob->setObjectId($objectId);
     if ($objectType == BatchJobObjectType::ENTRY) {
         $batchJob->setEntryId($objectId);
     } elseif ($objectType == BatchJobObjectType::ASSET) {
         $asset = assetPeer::retrieveById($objectId);
         if ($asset) {
             $batchJob->setEntryId($asset->getEntryId());
         }
     }
     $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     $jobType = IntegrationPlugin::getBatchJobTypeCoreValue(IntegrationBatchJobType::INTEGRATION);
     $batchJob = kJobsManager::addJob($batchJob, $data, $jobType, $data->getProviderType());
     return kJobsManager::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING);
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     $entry_id = $this->getPM("entry_id");
     $entry = entryPeer::retrieveByPK($entry_id);
     if (!$entry) {
         $this->addError(APIErrors::INVALID_ENTRY_ID, "entry", $entry_id);
     } else {
         $job = new BatchJob();
         $job->setJobType(BatchJobType::DVDCREATOR);
         $job->setStatus(BatchJob::BATCHJOB_STATUS_PENDING);
         //$job->setCheckAgainTimeout(time() + 10);
         $job->setEntryId($entry_id);
         $job->setPartnerId($entry->getPartnerId());
         $job->setSubpId($entry->getSubpId());
         $job->save();
         $wrapper = objectWrapperBase::getWrapperClass($job, objectWrapperBase::DETAIL_LEVEL_DETAILED);
         // TODO - remove this code when cache works properly when saving objects (in their save method)
         $wrapper->removeFromCache("batch_job", $job->getId());
         $this->addMsg("batchjob", $wrapper);
     }
 }
 /**
  * @param int $eventNotificationType
  * @param kEventNotificationDispatchJobData $jobData
  * @param string $partnerId
  * @param string $entryId
  * @param BatchJob $parentJob
  * @return BatchJob
  */
 protected function addEventNotificationDispatchJob($eventNotificationType, kEventNotificationDispatchJobData $jobData, $partnerId = null, $entryId = null, BatchJob $parentJob = null)
 {
     $jobType = EventNotificationPlugin::getBatchJobTypeCoreValue(EventNotificationBatchType::EVENT_NOTIFICATION_HANDLER);
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild($jobType, $eventNotificationType, false);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entryId);
         if (!$partnerId) {
             $partnerId = kCurrentContext::getCurrentPartnerId();
         }
         $batchJob->setPartnerId($partnerId);
     }
     KalturaLog::log("Creating event notification dispatch job on template id [" . $jobData->getTemplateId() . "] engine[{$eventNotificationType}]");
     $batchJob->setObjectId($entryId);
     $batchJob->setObjectType(BatchJobObjectType::ENTRY);
     $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     $batchJob = kJobsManager::addJob($batchJob, $jobData, $jobType, $eventNotificationType);
     $jobData->setJobId($batchJob->getId());
     $batchJob->setData($jobData);
     return kJobsManager::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING);
 }
 public static function addintegrationJob($objectType, $objectId, kIntegrationJobData $data)
 {
     $partnerId = kCurrentContext::getCurrentPartnerId();
     $providerType = $data->getProviderType();
     $integrationProvider = KalturaPluginManager::loadObject('IIntegrationProvider', $providerType);
     if (!$integrationProvider || !$integrationProvider->validatePermissions($partnerId)) {
         KalturaLog::err("partner {$partnerId} not permitted with provider type {$providerType}");
         return false;
     }
     $batchJob = new BatchJob();
     $batchJob->setPartnerId($partnerId);
     $batchJob->setObjectType($objectType);
     $batchJob->setObjectId($objectId);
     if ($objectType == BatchJobObjectType::ENTRY) {
         $batchJob->setEntryId($objectId);
     } elseif ($objectType == BatchJobObjectType::ASSET) {
         $asset = assetPeer::retrieveById($objectId);
         if ($asset) {
             $batchJob->setEntryId($asset->getEntryId());
         }
     }
     $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     $jobType = IntegrationPlugin::getBatchJobTypeCoreValue(IntegrationBatchJobType::INTEGRATION);
     $batchJob = kJobsManager::addJob($batchJob, $data, $jobType, $providerType);
     if ($integrationProvider->shouldSendCallBack()) {
         $jobId = $batchJob->getId();
         $ks = self::generateKs($partnerId, $jobId);
         $callBackUrl = "http://" . kConf::get('cdn_api_host');
         $callBackUrl .= "/api_v3/index.php/service/integration_integration/action/notify";
         $callBackUrl .= "/id/{$jobId}/ks/{$ks}";
         $data = $batchJob->getData();
         $data->setCallbackNotificationUrl($callBackUrl);
         $batchJob->setData($data);
     }
     return kJobsManager::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING);
 }
Exemple #9
0
 /**
  * Function adds bulk upload job to the queue
  * @param Partner $partner
  * @param kBulkUploadJobData $jobData
  * @param string $bulkUploadType
  * @throws APIException
  * @return BatchJob
  */
 public static function addBulkUploadJob(Partner $partner, kBulkUploadJobData $jobData, $bulkUploadType = null, $objectId = null, $objectType = null)
 {
     KalturaLog::debug("adding BulkUpload job");
     $job = new BatchJob();
     $job->setPartnerId($partner->getId());
     $job->setJobType(BatchJobType::BULKUPLOAD);
     $job->setJobSubType($bulkUploadType);
     if (!is_null($objectId) && !is_null($objectType)) {
         $job->setObjectId($objectId);
         $job->setObjectType($objectType);
     }
     if (is_null($jobData)) {
         throw new APIException(APIErrors::BULK_UPLOAD_BULK_UPLOAD_TYPE_NOT_VALID, $bulkUploadType);
     }
     $job->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     $job = kJobsManager::addJob($job, $jobData, BatchJobType::BULKUPLOAD, $bulkUploadType);
     if (!is_null($jobData->getFilePath())) {
         $syncKey = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD);
         //		kFileSyncUtils::file_put_contents($syncKey, file_get_contents($csvFileData["tmp_name"]));
         try {
             kFileSyncUtils::moveFromFile($jobData->getFilePath(), $syncKey, true);
         } catch (Exception $e) {
             KalturaLog::err($e);
             throw new APIException(APIErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR);
         }
         $filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
         $jobData->setFilePath($filePath);
     }
     if (!$jobData->getBulkUploadObjectType()) {
         $jobData->setBulkUploadObjectType(BulkUploadObjectType::ENTRY);
     }
     if ($jobData->getBulkUploadObjectType() == BulkUploadObjectType::ENTRY && !$jobData->getObjectData()->getConversionProfileId()) {
         $jobData->setConversionProfileId($partner->getDefaultConversionProfileId());
         $kmcVersion = $partner->getKmcVersion();
         $check = null;
         if ($kmcVersion < 2) {
             $check = ConversionProfilePeer::retrieveByPK($jobData->getConversionProfileId());
         } else {
             $check = conversionProfile2Peer::retrieveByPK($jobData->getConversionProfileId());
         }
         if (!$check) {
             throw new APIException(APIErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $jobData->getConversionProfileId());
         }
     }
     $job->setData($jobData);
     return kJobsManager::updateBatchJob($job, BatchJob::BATCHJOB_STATUS_PENDING);
 }
Exemple #10
0
 /**
  * @return BatchJob
  */
 public function createChild($same_root = true)
 {
     $child = new BatchJob();
     $child->setStatus(self::BATCHJOB_STATUS_PENDING);
     $child->setParentJobId($this->id);
     $child->setPartnerId($this->partner_id);
     $child->setEntryId($this->entry_id);
     $child->setPriority($this->priority);
     $child->setSubpId($this->subp_id);
     $child->setBulkJobId($this->bulk_job_id);
     $child->setDc($this->dc);
     if ($same_root && $this->root_job_id) {
         $child->setRootJobId($this->root_job_id);
     } else {
         $child->setRootJobId($this->id);
     }
     $child->save();
     return $child;
 }
 /**
  * @return BatchJob
  */
 public function createChild($same_root = true, $dc = null)
 {
     $child = new BatchJob();
     $child->setStatus(self::BATCHJOB_STATUS_PENDING);
     $child->setParentJobId($this->id);
     $child->setPartnerId($this->partner_id);
     $child->setEntryId($this->entry_id);
     $child->setPriority($this->priority);
     $child->setSubpId($this->subp_id);
     $child->setBulkJobId($this->bulk_job_id);
     // the condition is required in the special case of file_sync import jobs which are created on one dc but run from the other
     $child->setDc($dc === null ? $this->dc : $dc);
     if ($same_root && $this->root_job_id) {
         $child->setRootJobId($this->root_job_id);
     } else {
         $child->setRootJobId($this->id);
     }
     $child->save();
     return $child;
 }
 public static function addFutureDeletionJob(BatchJob $parentJob = null, $entryId = null, Partner $partner, $syncKey, $localFileSyncPath, $dc)
 {
     $deleteFileData = new kDeleteFileJobData();
     $deleteFileData->setLocalFileSyncPath($localFileSyncPath);
     $deleteFileData->setSyncKey($syncKey);
     if ($parentJob) {
         $batchJob = $parentJob->createChild(false);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entryId);
         $batchJob->setPartnerId($partner->getId());
     }
     $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_RETRY);
     $batchJob->setCheckAgainTimeout(12 * 60 * 60);
     $batchJob->setDc($dc);
     KalturaLog::log("Creating File Delete job, from data center id: " . $deleteFileData->getDC() . " with source file: " . $deleteFileData->getLocalFileSyncPath());
     return self::addJob($batchJob, $deleteFileData, BatchJobType::DELETE_FILE);
 }
 /**
  * @param ScheduledTaskProfile $scheduledTaskProfile
  * @param kScheduledTaskJobData $jobData
  * @return BatchJob
  */
 protected function createScheduledTaskJob(ScheduledTaskProfile $scheduledTaskProfile, kScheduledTaskJobData $jobData)
 {
     $scheduledTaskProfileId = $scheduledTaskProfile->getId();
     $jobType = ScheduledTaskPlugin::getBatchJobTypeCoreValue(ScheduledTaskBatchType::SCHEDULED_TASK);
     $objectType = ScheduledTaskPlugin::getBatchJobObjectTypeCoreValue(ScheduledTaskBatchJobObjectType::SCHEDULED_TASK_PROFILE);
     KalturaLog::log("Creating scheduled task dry run job for profile [" . $scheduledTaskProfileId . "]");
     $batchJob = new BatchJob();
     $batchJob->setPartnerId($scheduledTaskProfile->getPartnerId());
     $batchJob->setObjectId($scheduledTaskProfileId);
     $batchJob->setObjectType($objectType);
     $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_PENDING);
     $batchJob = kJobsManager::addJob($batchJob, $jobData, $jobType);
     return $batchJob;
 }