Exemplo n.º 1
0
 /**
  * batch freeExclusiveJobAction action allows to get a generic BatchJob
  *
  * @action freeExclusiveJob
  * @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
  * @param bool $resetExecutionAttempts Resets the job execution attampts to zero
  * @return KalturaFreeJobResponse
  */
 function freeExclusiveJobAction($id, KalturaExclusiveLockKey $lockKey, $jobType, $resetExecutionAttempts = false)
 {
     $jobType = kPluginableEnumsManager::apiToCore('BatchJobType', $jobType);
     $job = BatchJobPeer::retrieveByPK($id);
     // verifies that the job is of the right type
     if ($job->getJobType() != $jobType) {
         throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, $lockKey, null);
     }
     $job = kBatchManager::freeExclusiveBatchJob($id, $lockKey->toObject(), $resetExecutionAttempts);
     $batchJob = new KalturaBatchJob();
     // start from blank
     $batchJob->fromBatchJob($job);
     // gets queues length
     $c = new Criteria();
     $c->add(BatchJobLockPeer::STATUS, array(KalturaBatchJobStatus::PENDING, KalturaBatchJobStatus::RETRY, KalturaBatchJobStatus::ALMOST_DONE), Criteria::IN);
     $c->add(BatchJobLockPeer::JOB_TYPE, $jobType);
     $c->add(BatchJobLockPeer::DC, kDataCenterMgr::getCurrentDcId());
     $queueSize = BatchJobLockPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
     if (!$queueSize) {
         // gets queues length
         $c = new Criteria();
         $c->add(BatchJobLockPeer::BATCH_INDEX, null, Criteria::ISNOTNULL);
         $c->add(BatchJobLockPeer::EXPIRATION, time(), Criteria::GREATER_THAN);
         $c->add(BatchJobLockPeer::EXECUTION_ATTEMPTS, BatchJobLockPeer::getMaxExecutionAttempts($jobType), Criteria::LESS_THAN);
         $c->add(BatchJobLockPeer::DC, kDataCenterMgr::getCurrentDcId());
         $c->add(BatchJobLockPeer::JOB_TYPE, $jobType);
         $queueSize = BatchJobLockPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
     }
     $response = new KalturaFreeJobResponse();
     $response->job = $batchJob;
     $response->jobType = $jobType;
     $response->queueSize = $queueSize;
     return $response;
 }
Exemplo n.º 2
0
 public static function getExpiredJobs()
 {
     $jobTypes = kPluginableEnumsManager::coreValues('BatchJobType');
     $executionAttempts2jobTypes = array();
     // Map between max execution attempts and job types
     foreach ($jobTypes as $jobType) {
         $executionAttempts = BatchJobLockPeer::getMaxExecutionAttempts($jobType);
         if (array_key_exists($executionAttempts, $executionAttempts2jobTypes)) {
             $executionAttempts2jobTypes[$executionAttempts][] = $jobType;
         } else {
             $executionAttempts2jobTypes[$executionAttempts] = array($jobType);
         }
     }
     // create query
     $c = new Criteria();
     $c->add(BatchJobLockPeer::STATUS, BatchJob::BATCHJOB_STATUS_FATAL, Criteria::NOT_EQUAL);
     $c->add(BatchJobLockPeer::DC, kDataCenterMgr::getCurrentDcId());
     // each DC should clean its own jobs
     // Query for each job type
     $batchJobLocks = array();
     foreach ($executionAttempts2jobTypes as $execAttempts => $jobTypes) {
         $typedCrit = clone $c;
         $typedCrit->add(BatchJobLockPeer::EXECUTION_ATTEMPTS, $execAttempts, Criteria::GREATER_THAN);
         $typedCrit->add(BatchJobLockPeer::JOB_TYPE, $jobTypes, Criteria::IN);
         $typedJobs = BatchJobLockPeer::doSelect($typedCrit, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
         foreach ($typedJobs as $typedJob) {
             $batchJobLocks[$typedJob->getId()] = $typedJob;
         }
     }
     // get matching batch jobs
     return BatchJobPeer::retrieveByPKs(array_keys($batchJobLocks));
 }
Exemplo n.º 3
0
 public function updatedJob(BatchJob $dbBatchJob)
 {
     $dbBatchJobLock = $dbBatchJob->getBatchJobLock();
     try {
         if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED || $dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FATAL) {
             kJobsManager::abortChildJobs($dbBatchJob);
         }
         $jobType = $dbBatchJob->getJobType();
         switch ($jobType) {
             case BatchJobType::IMPORT:
                 $dbBatchJob = $this->updatedImport($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::EXTRACT_MEDIA:
                 $dbBatchJob = $this->updatedExtractMedia($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::CONVERT:
                 $dbBatchJob = $this->updatedConvert($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::POSTCONVERT:
                 $dbBatchJob = $this->updatedPostConvert($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::BULKUPLOAD:
                 $dbBatchJob = $this->updatedBulkUpload($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::CONVERT_PROFILE:
                 $dbBatchJob = $this->updatedConvertProfile($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::BULKDOWNLOAD:
                 $dbBatchJob = $this->updatedBulkDownload($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::PROVISION_PROVIDE:
                 $dbBatchJob = $this->updatedProvisionProvide($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::PROVISION_DELETE:
                 $dbBatchJob = $this->updatedProvisionDelete($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::CONVERT_COLLECTION:
                 $dbBatchJob = $this->updatedConvertCollection($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::STORAGE_EXPORT:
                 $dbBatchJob = $this->updatedStorageExport($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::MOVE_CATEGORY_ENTRIES:
                 $dbBatchJob = $this->updatedMoveCategoryEntries($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::STORAGE_DELETE:
                 $dbBatchJob = $this->updatedStorageDelete($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::CAPTURE_THUMB:
                 $dbBatchJob = $this->updatedCaptureThumb($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::DELETE_FILE:
                 $dbBatchJob = $this->updatedDeleteFile($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::INDEX:
                 $dbBatchJob = $this->updatedIndex($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::COPY:
                 $dbBatchJob = $this->updatedCopy($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::DELETE:
                 $dbBatchJob = $this->updatedDelete($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::CONCAT:
                 $dbBatchJob = $this->updatedConcat($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::CONVERT_LIVE_SEGMENT:
                 $dbBatchJob = $this->updatedConvertLiveSegment($dbBatchJob, $dbBatchJob->getData());
                 break;
             case BatchJobType::LIVE_REPORT_EXPORT:
                 $dbBatchJob = $this->updatedLiveReportExport($dbBatchJob, $dbBatchJob->getData());
                 break;
             default:
                 break;
         }
         if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_RETRY) {
             if ($dbBatchJobLock && $dbBatchJobLock->getExecutionAttempts() >= BatchJobLockPeer::getMaxExecutionAttempts($jobType)) {
                 $dbBatchJob = kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_FAILED);
             }
         }
         if (in_array($dbBatchJob->getStatus(), BatchJobPeer::getClosedStatusList())) {
             $jobEntry = $dbBatchJob->getEntry();
             if ($jobEntry && $jobEntry->getMarkedForDeletion()) {
                 myEntryUtils::deleteEntry($jobEntry, null, true);
             }
         }
     } catch (Exception $ex) {
         self::alert($dbBatchJob, $ex);
         KalturaLog::err("Error:" . $ex->getMessage());
     }
     return true;
 }