Exemplo n.º 1
0
 /**
  * Returns the number of related BatchJobLock objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related BatchJobLock objects.
  * @throws     PropelException
  */
 public function countBatchJobLocks(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(BatchJobPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collBatchJobLocks === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(BatchJobLockPeer::BATCH_JOB_ID, $this->id);
             $count = BatchJobLockPeer::doCount($criteria, false, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(BatchJobLockPeer::BATCH_JOB_ID, $this->id);
             if (!isset($this->lastBatchJobLockCriteria) || !$this->lastBatchJobLockCriteria->equals($criteria)) {
                 $count = BatchJobLockPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collBatchJobLocks);
             }
         } else {
             $count = count($this->collBatchJobLocks);
         }
     }
     return $count;
 }
Exemplo n.º 2
0
 private static function getQueue(Criteria $c, $schedulerId, $workerId, $max_exe_attempts)
 {
     $schd = BatchJobLockPeer::SCHEDULER_ID;
     $work = BatchJobLockPeer::WORKER_ID;
     $stat = BatchJobLockPeer::STATUS;
     $atmp = BatchJobLockPeer::EXECUTION_ATTEMPTS;
     $expr = BatchJobLockPeer::EXPIRATION;
     $recheck = BatchJobLockPeer::START_AT;
     $schd_id = $schedulerId;
     $work_id = $workerId;
     $now = time();
     $now_str = date('Y-m-d H:i:s', $now);
     // same workers unfinished jobs
     $query1 = "(\n\t\t\t\t\t\t\t{$schd} = {$schd_id}\n\t\t\t\t\t\tAND {$work} = {$work_id}\n\t\t\t\t\t\tAND {$stat} IN (" . BatchJobPeer::getInProcStatusList() . ")\n\t\t\t\t\t)";
     //	"others unfinished jobs " - the expiration should be SMALLER than the current time to make sure the job is not
     // being processed
     $unclosedStatuses = BatchJobPeer::getUnClosedStatusList();
     $unclosedStatuses = implode(',', $unclosedStatuses);
     $query2 = "(\n\t\t\t\t\t\t\t{$stat} IN ({$unclosedStatuses})\n\t\t\t\t\t\tAND\t{$expr} <= '{$now_str}'\n\t\t\t\t\t)";
     // "retry jobs"
     $query3 = "(\n\t\t\t\t\t\t{$stat} IN (" . BatchJob::BATCHJOB_STATUS_RETRY . ", " . BatchJob::BATCHJOB_STATUS_ALMOST_DONE . ")\n\t\t\t\t\t\tAND {$recheck} <= '{$now_str}'\n\t\t\t\t\t)";
     // "max attempts jobs"
     $queryMaxAttempts = "(\n\t\t\t\t\t\t\t\t{$atmp} <= {$max_exe_attempts}\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t{$atmp} IS NULL\n\t\t\t\t\t\t\t)";
     $crit1 = $c->getNewCriterion($stat, BatchJob::BATCHJOB_STATUS_PENDING);
     if ($schedulerId && $workerId) {
         $crit1->addOr($c->getNewCriterion($schd, $query1, Criteria::CUSTOM));
     }
     $crit1->addOr($c->getNewCriterion($schd, $query2, Criteria::CUSTOM));
     $crit1->addOr($c->getNewCriterion($schd, $query3, Criteria::CUSTOM));
     $c->addAnd($crit1);
     $c->addAnd($c->getNewCriterion($atmp, $queryMaxAttempts, Criteria::CUSTOM));
     $c->addAnd($c->getNewCriterion(BatchJobLockPeer::DC, kDataCenterMgr::getCurrentDcId()));
     return BatchJobLockPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
 }
Exemplo n.º 3
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;
 }