public function execute()
 {
     $jobId = $this->getRequestParameter("id");
     $partnerId = $this->getRequestParameter("pid");
     $type = $this->getRequestParameter("type");
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::ID, $jobId);
     $c->addAnd(BatchJobPeer::PARTNER_ID, $partnerId);
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if (!$batchJob) {
         die("File not found");
     }
     header("Content-Type: text/plain; charset=UTF-8");
     if ($type == "log") {
         $bulkUploadResults = BulkUploadResultPeer::retrieveByBulkUploadId($jobId);
         if (!count($bulkUploadResults)) {
             $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADLOG);
             if (kFileSyncUtils::file_exists($syncKey, true)) {
                 $content = kFileSyncUtils::file_get_contents($syncKey, true);
                 echo $content;
                 die;
             }
             die("Log file is not ready");
         }
         $STDOUT = fopen('php://output', 'w');
         $data = $batchJob->getData();
         foreach ($bulkUploadResults as $bulkUploadResult) {
             $values = array($bulkUploadResult->getTitle(), $bulkUploadResult->getDescription(), $bulkUploadResult->getTags(), $bulkUploadResult->getUrl(), $bulkUploadResult->getContentType());
             if ($data instanceof kBulkUploadJobData && $data->getCsvVersion() > kBulkUploadJobData::BULK_UPLOAD_CSV_VERSION_V1) {
                 $values[] = $bulkUploadResult->getConversionProfileId();
                 $values[] = $bulkUploadResult->getAccessControlProfileId();
                 $values[] = $bulkUploadResult->getCategory();
                 $values[] = $bulkUploadResult->getScheduleStartDate('Y-m-d\\TH:i:s');
                 $values[] = $bulkUploadResult->getScheduleEndDate('Y-m-d\\TH:i:s');
                 $values[] = $bulkUploadResult->getThumbnailUrl();
                 $values[] = $bulkUploadResult->getPartnerData();
             }
             $values[] = $bulkUploadResult->getEntryId();
             $values[] = $bulkUploadResult->getEntryStatus();
             $values[] = $bulkUploadResult->getErrorDescription();
             fputcsv($STDOUT, $values);
         }
         fclose($STDOUT);
     } else {
         $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADCSV);
         if (kFileSyncUtils::file_exists($syncKey, true)) {
             $content = kFileSyncUtils::file_get_contents($syncKey, true);
             echo $content;
             die;
         } else {
             die("File not found");
         }
     }
     die;
     //  no template needed
 }
Ejemplo n.º 2
0
 /**
  * Get bulk upload batch job by id
  *
  * @action get
  * @param int $id
  * @return KalturaBulkUpload
  */
 function getAction($id)
 {
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::ID, $id);
     $c->addAnd(BatchJobPeer::PARTNER_ID, $this->getPartnerId());
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if (!$batchJob) {
         throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_NOT_FOUND, $id);
     }
     $ret = new KalturaBulkUpload();
     $ret->fromObject($batchJob);
     return $ret;
 }
 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);
     }
 }
Ejemplo n.º 4
0
 public function getImportInfo()
 {
     if ($this->getStatus() == entryStatus::IMPORT) {
         $c = new Criteria();
         $c->add(BatchJobPeer::ENTRY_ID, $this->getId());
         $c->addDescendingOrderByColumn(BatchJobPeer::ID);
         $import = BatchJobPeer::doSelectOne($c);
         return $import;
     }
     return null;
 }
 /**
  * batch resetJobExecutionAttempts action resets the execution attempts of the job 
  * 
  * @action resetJobExecutionAttempts
  * @param int $id The id of the job
  * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism
  * @param KalturaBatchJobType $jobType The type of the job  
  * @throws KalturaErrors::UPDATE_EXCLUSIVE_JOB_FAILED
  * @throws KalturaErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE
  */
 function resetJobExecutionAttemptsAction($id, KalturaExclusiveLockKey $lockKey, $jobType)
 {
     $jobType = kPluginableEnumsManager::apiToCore('BatchJobType', $jobType);
     $c = new Criteria();
     $c->add(BatchJobPeer::ID, $id);
     $c->add(BatchJobPeer::SCHEDULER_ID, $lockKey->schedulerId);
     $c->add(BatchJobPeer::WORKER_ID, $lockKey->workerId);
     $c->add(BatchJobPeer::BATCH_INDEX, $lockKey->batchIndex);
     $job = BatchJobPeer::doSelectOne($c);
     if (!$job) {
         throw new KalturaAPIException(KalturaErrors::UPDATE_EXCLUSIVE_JOB_FAILED, $id, $lockKey->schedulerId, $lockKey->workerId, $lockKey->batchIndex);
     }
     // verifies that the job is of the right type
     if ($job->getJobType() != $jobType) {
         throw new KalturaAPIException(KalturaErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, $lockKey, null);
     }
     $job->setExecutionAttempts(0);
     $job->save();
 }
Ejemplo n.º 6
0
 private static function getParentJobForWaitingAssetConversion($entryId, BatchJob $parentJob = null)
 {
     if ($parentJob && $parentJob->getJobType() == BatchJobType::POSTCONVERT) {
         //In case the flavor conversion is triggered by the ingested flavor add the conversion job
         //under the convert profile job if available
         $c = new Criteria();
         $c->add(BatchJobPeer::ENTRY_ID, $entryId);
         $c->add(BatchJobPeer::JOB_TYPE, BatchJobType::CONVERT_PROFILE);
         $statuses = BatchJobPeer::getUnClosedStatusList();
         $statuses[] = BatchJob::BATCHJOB_STATUS_ALMOST_DONE;
         $c->add(BatchJobPeer::STATUS, $statuses, Criteria::IN);
         $batchJob = BatchJobPeer::doSelectOne($c);
         if ($batchJob) {
             return $batchJob;
         }
     }
     return $parentJob;
 }
Ejemplo n.º 7
0
 /**
  * 
  * @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;
 }
Ejemplo n.º 8
0
 /**
  * Aborts the bulk upload and all its child jobs
  * 
  * @action abort
  * @param int $id job id
  * @return KalturaBulkUpload
  */
 function abortAction($id)
 {
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::ID, $id);
     $c->addAnd(BatchJobPeer::PARTNER_ID, $this->getPartnerId());
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if (!$batchJob) {
         throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_NOT_FOUND, $id);
     }
     kJobsManager::abortJob($id, BatchJobType::BULKUPLOAD, true);
     $batchJobLog = BatchJobLogPeer::retrieveByBatchJobId($id);
     $ret = new KalturaBulkUpload();
     if ($batchJobLog) {
         $ret->fromObject($batchJobLog, $this->getResponseProfile());
     }
     return $ret;
 }
Ejemplo n.º 9
0
 private static function activateConvertProfileJob($entryId, $localFilePath)
 {
     $c = new Criteria();
     $c->add(BatchJobPeer::ENTRY_ID, $entryId);
     $c->add(BatchJobPeer::JOB_TYPE, BatchJobType::CONVERT_PROFILE);
     $c->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if ($batchJob) {
         $data = $batchJob->getData();
         $data->setInputFileSyncLocalPath($localFilePath);
         $batchJob->setData($data);
         kJobsManager::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING);
         return true;
     } else {
         return false;
     }
 }
 public function resetFeaturesStatusByType($type)
 {
     $openStatuses = array(BatchJob::BATCHJOB_STATUS_ALMOST_DONE, BatchJob::BATCHJOB_STATUS_RETRY, BatchJob::BATCHJOB_STATUS_PENDING, BatchJob::BATCHJOB_STATUS_QUEUED, BatchJob::BATCHJOB_STATUS_PROCESSING, BatchJob::BATCHJOB_STATUS_PROCESSED, BatchJob::BATCHJOB_STATUS_MOVEFILE);
     $criteria = new Criteria();
     $criteria->add(BatchJobPeer::PARTNER_ID, $this->getId());
     $criteria->add(BatchJobPeer::JOB_TYPE, BatchJobType::INDEX);
     $criteria->add(BatchJobPeer::JOB_SUB_TYPE, $type);
     $criteria->add(BatchJobPeer::STATUS, $openStatuses, Criteria::IN);
     $batchJob = BatchJobPeer::doSelectOne($criteria);
     $featuresStatuses = $this->getFeaturesStatus();
     if ($batchJob) {
         $newFeatureStatus = new kFeatureStatus();
         $newFeatureStatus->setType($type);
         $newFeatureStatus->setValue(1);
         $featuresStatuses[$type] = $newFeatureStatus;
     } elseif (isset($featuresStatuses[$type])) {
         unset($featuresStatuses[$type]);
     }
     $this->setFeaturesStatus($featuresStatuses);
     $this->setUpdatedAt(time());
     $this->save();
 }
Ejemplo n.º 11
0
 /**
  * Aborts the bulk upload and all its child jobs
  * 
  * @action abort
  * @param bigint $id job id
  * @return KalturaBulkUpload
  */
 public function abortAction($id)
 {
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::ID, $id);
     $c->addAnd(BatchJobPeer::PARTNER_ID, $this->getPartnerId());
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if (!$batchJob) {
         $c = new Criteria();
         $c->addAnd(BatchJobLogPeer::JOB_ID, $id);
         $c->addAnd(BatchJobLogPeer::PARTNER_ID, $this->getPartnerId());
         $c->addAnd(BatchJobLogPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
         $crit = $c->getNewCriterion(BatchJobLogPeer::ABORT, null);
         $critOr = $c->getNewCriterion(BatchJobLogPeer::ABORT, 0);
         $crit->addOr($critOr);
         $c->add($crit);
         $batchJobLog = BatchJobLogPeer::doSelectOne($c);
         if (!$batchJobLog) {
             throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_NOT_FOUND, $id);
         }
         $batchJobLog->setAbort(BatchJobExecutionStatus::ABORTED);
         $batchJobLog->save();
     } else {
         kJobsManager::abortJob($id, BatchJobType::BULKUPLOAD, true);
     }
     $batchJobLog = BatchJobLogPeer::retrieveByBatchJobId($id);
     $ret = new KalturaBulkUpload();
     $ret->fromObject($batchJobLog, $this->getResponseProfile());
     return $ret;
 }