/**
  * 
  * @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;
 }
예제 #2
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;
 }
예제 #3
0
 public static function postLockUpdate(kExclusiveLockKey $lockKey, array $exclusive_objects_ids, $con)
 {
     $batchJobs = BatchJobPeer::retrieveByPKs($exclusive_objects_ids);
     foreach ($batchJobs as $batchJob) {
         /* @var $batchJob BatchJob */
         // Set history
         $uniqueId = new UniqueId();
         $historyRecord = new kBatchHistoryData();
         $historyRecord->setWorkerId($lockKey->getWorkerId());
         $historyRecord->setSchedulerId($lockKey->getSchedulerId());
         $historyRecord->setBatchIndex($lockKey->getBatchIndex());
         $historyRecord->setHostName(isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : gethostname());
         $historyRecord->setSessionId((string) $uniqueId);
         $batchJob->addHistoryRecord($historyRecord);
         // Set fields
         $batchJob->setLastWorkerId($lockKey->getWorkerId());
         $batchJob->setLastSchedulerId($lockKey->getSchedulerId());
         // Set fields from batch job lock
         $lockInfo = $batchJob->getLockInfo();
         $lockInfo->setLockVersion($lockInfo->getLockVersion() + 1);
         $batchJob->setLockInfo($lockInfo);
         $batchJob->save($con);
     }
     return $batchJobs;
 }