Exemplo n.º 1
0
 /**
  *
  * @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;
 }
Exemplo n.º 2
0
 /**
  * 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());
     }
     $dbBatchJobLock = BatchJobLockPeer::retrieveByPK($jobId);
     $job = new KalturaBatchJob();
     $job->fromBatchJob($dbBatchJob, $dbBatchJobLock);
     $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;
 }
Exemplo n.º 3
0
 public function fromStatisticsObject($dbBatchJob, $dbLockObj = null)
 {
     $dbBatchJobLock = BatchJobLockPeer::retrieveByPK($dbBatchJob->getId());
     $this->fromBatchJob($dbBatchJob, $dbBatchJobLock);
     if (!$dbBatchJob instanceof BatchJob) {
         return $this;
     }
     $entry = $dbBatchJob->getEntry(true);
     if ($entry) {
         $this->entryName = $entry->getName();
     }
     return $this;
 }
Exemplo n.º 4
0
 public static function shouldCreateLockObject(BatchJob $batchJob, $isNew, PropelPDO $con = null)
 {
     if ($isNew) {
         if (in_array($batchJob->getStatus(), self::getSchedulingRequiredStatusList())) {
             return true;
         }
         return false;
     }
     $oldStatus = $batchJob->getColumnsOldValue(BatchJobPeer::STATUS);
     $oldValueInClosed = is_null($oldStatus) ? false : in_array($oldStatus, BatchJobPeer::getClosedStatusList());
     $newValue = $batchJob->getStatus();
     $newValueInOpen = in_array($newValue, BatchJobPeer::getUnClosedStatusList());
     // if the object is not a new object, a batch_job_lock object should exist.
     // an exception is when we move from a closed state to a open open.
     // f.i. retry request of an entry that was in closed status and we now restarted it.
     if (!($oldValueInClosed && $newValueInOpen)) {
         return false;
     }
     $lockEntry = BatchJobLockPeer::retrieveByPK($batchJob->getId());
     if ($lockEntry === null) {
         return true;
     }
     return false;
 }