public function getLockedJobs() { $c = new Criteria(); $c->add(BatchJobLockPeer::BATCH_INDEX, null, Criteria::ISNOTNULL); $c->add(BatchJobLockPeer::SCHEDULER_ID, $this->scheduler_configured_id); $c->add(BatchJobLockPeer::WORKER_ID, $this->configured_id); return BatchJobLockPeer::doSelect($c, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2)); }
public function getFieldNameFromPeer($field_name) { if ($this->queryFromBatchJob) { return BatchJobPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME); } else { return BatchJobLockPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME); } }
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; }
public function resetFeaturesStatusByType($type) { $criteria = new Criteria(); $criteria->add(BatchJobLockPeer::PARTNER_ID, $this->getId()); $criteria->add(BatchJobLockPeer::JOB_TYPE, BatchJobType::INDEX); $criteria->add(BatchJobLockPeer::JOB_SUB_TYPE, $type); $batchJob = BatchJobLockPeer::doSelectOne($criteria); if ($batchJob) { $this->addFeaturesStatus($type); } else { $this->removeFeaturesStatus($type); } }
/** * @param int $entryId */ public static function boostEntryJobs($entryId) { $entrydb = entryPeer::retrieveByPK($entryId); if (!$entrydb) { throw new APIException(APIErrors::ENTRY_ID_NOT_FOUND, $entryId); } //Retrieve all batch jobs associated to the entry $batchJobs = BatchJobLockPeer::retrieveByEntryId($entryId); foreach ($batchJobs as $job) { /* @var $job BatchJobLock */ //Boost the job by setting priority and urjeny to 1 $job->setPriority(1); $job->setUrgency(1); } }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = BatchJobLockPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setJobType($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setJobSubType($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setObjectId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setObjectType($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setEstimatedEffort($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setStatus($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setStartAt($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setCreatedAt($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setPriority($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setUrgency($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setEntryId($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setPartnerId($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setSchedulerId($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setWorkerId($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setBatchIndex($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setExpiration($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setExecutionAttempts($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setVersion($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { $this->setDc($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { $this->setBatchJobId($arr[$keys[20]]); } if (array_key_exists($keys[21], $arr)) { $this->setCustomData($arr[$keys[21]]); } if (array_key_exists($keys[22], $arr)) { $this->setBatchVersion($arr[$keys[22]]); } if (array_key_exists($keys[23], $arr)) { $this->setRootJobId($arr[$keys[23]]); } }
public static function deleteEntry(entry $entry, $partner_id = null, $onlyIfAllJobsDone = false) { if ($entry->getStatus() == entryStatus::DELETED || $entry->getStatus() == entryStatus::BLOCKED) { return; } // don't do this twice ! if ($onlyIfAllJobsDone) { $dbEntryBatchJobLocks = BatchJobLockPeer::retrieveByEntryId($entry->getId()); foreach ($dbEntryBatchJobLocks as $jobLock) { /* @var $jobLock BatchJobLock */ KalturaLog::info("Entry [" . $entry->getId() . "] still has an unhandled batchjob [" . $jobLock->getId() . "] with status [" . $jobLock->getStatus() . "] - aborting deletion process."); //mark entry for later deletion $entry->setMarkedForDeletion(true); $entry->save(); return; } } KalturaLog::log("myEntryUtils::delete Entry [" . $entry->getId() . "] Partner [" . $entry->getPartnerId() . "]"); kJobsManager::abortEntryJobs($entry->getId()); $media_type = $entry->getMediaType(); $need_to_fix_roughcut = false; $thumb_template_file = "&deleted_image.jpg"; KalturaLog::log("media type [{$media_type}]"); switch ($media_type) { case entry::ENTRY_MEDIA_TYPE_AUDIO: $template_file = "&deleted_audio.flv"; $need_to_fix_roughcut = true; break; case entry::ENTRY_MEDIA_TYPE_IMAGE: $template_file = "&deleted_image.jpg"; $need_to_fix_roughcut = false; // no need to add a batch job for images break; case entry::ENTRY_MEDIA_TYPE_VIDEO: $template_file = "&deleted_video.flv"; $need_to_fix_roughcut = true; break; case entry::ENTRY_MEDIA_TYPE_SHOW: default: $template_file = "&deleted_rc.xml"; $need_to_fix_roughcut = false; break; } if ($entry->getType() == entryType::LIVE_STREAM) { kJobsManager::addProvisionDeleteJob(null, $entry); } // in this case we'll need some batch job to fix all related roughcuts for this entry // use the batch_job mechanism to indicate there is a deleted entry to handle if ($need_to_fix_roughcut) { // Should use a different job type // BatchJob::createDeleteEntryJob ( $entry ); } $entry->putInCustomData("deleted_original_data", $entry->getData()); $entry->putInCustomData("deleted_original_thumb", $entry->getThumbnail()); $content_path = myContentStorage::getFSContentRootPath(); // Remarked by Tan-Tan 27/09/2010 // Handled by kObjectDeleteHandler // $currentDataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath // $currentDataEditKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT); // replaced__getDataPathEdit // $currentThumbKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath $entry->setData($entry->getData()); // once to increment the verions $entry->setData($template_file); // the other to set the template $entry->setThumbnail($entry->getThumbnail()); // once to increment the verions $entry->setThumbnail($thumb_template_file); // the other to set the template // Remarked by Tan-Tan 27/09/2010 // Handled by kObjectDeleteHandler // // move file so there will be no access to it // $deleted_content = kFileSyncUtils::deleteSyncFileForKey($currentDataKey); // $deleted_content .= "|" . kFileSyncUtils::deleteSyncFileForKey($currentDataEditKey,false); // for some entries there may not be an edit version // $deleted_content .= "|" . kFileSyncUtils::deleteSyncFileForKey($currentThumbKey,false); // for some entries (empty mix / audio) there may not be a thumb FileSync // Remarked by Tan-Tan 27/09/2010 // $deleted_content is always null anyway // $entry->putInCustomData( "deleted_file_path" , $deleted_content ? $deleted_content : serialize($currentDataKey) ) ; $entry->setStatus(entryStatus::DELETED); //$entry->setCategories(""); // make sure the moderation_status is set to moderation::MODERATION_STATUS_DELETE $entry->setModerationStatus(moderation::MODERATION_STATUS_DELETE); $entry->setModifiedAt(time()); $entry->save(); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_DELETE, $entry, null, null, null, null, $entry->getId()); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(BatchJobLockPeer::DATABASE_NAME); $criteria->add(BatchJobLockPeer::ID, $pks, Criteria::IN); $objs = BatchJobLockPeer::doSelect($criteria, $con); } return $objs; }
public function postUpdate(PropelPDO $con = null) { if (!$this->alreadyInSave && BatchJobLockPeer::shouldCreateLockObject($this, false, $con)) { BatchJobLockPeer::createLockObject($this); } return parent::postUpdate($con); }
$c->add(BatchJobLockPeer::STATUS, $jobStatus); $c->add(BatchJobLockPeer::JOB_TYPE, $jobType); if (!is_null($jobSubType)) { $c->add(BatchJobLockPeer::JOB_SUB_TYPE, $jobSubType); } if (!is_null($partnerId)) { if ($partnerId[0] == '!') { $c->add(BatchJobLockPeer::PARTNER_ID, substr($partnerId, 1), Criteria::NOT_EQUAL); } else { $c->add(BatchJobLockPeer::PARTNER_ID, $partnerId); } } $c->setLimit(CHUNK_SIZE); $movedJobsCount = 0; while ($movedJobsCount < $maxMovedJobs) { $jobLocks = BatchJobLockPeer::doSelect($c, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2)); if (!$jobLocks) { break; } $initialMovedJobsCount = $movedJobsCount; foreach ($jobLocks as $jobLock) { /* @var $jobLock BatchJobLock */ /* @var $job BatchJob */ $job = $jobLock->getBatchJob(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2)); // check whether the job can be moved $jobData = $job->getData(); /* @var $jobData kConvartableJobData */ $srcFileSyncs = $jobData->getSrcFileSyncs(); if (count($srcFileSyncs) != 1) { continue; }
private static function getMaxQuotaForPartner($partnerLoadRecord) { // Insert $partner = PartnerPeer::retrieveByPK($partnerLoadRecord->getPartnerId()); $maxQuota = $partner->getJobTypeQuota($partnerLoadRecord->getJobType(), $partnerLoadRecord->getJobSubType()); if (!$maxQuota) { $maxQuota = BatchJobLockPeer::getMaxJobsForPartner($partnerLoadRecord->getJobType()); } return $maxQuota; }
/** * 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; }
/** * 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; }
public function objectChanged(BaseObject $object, array $modifiedColumns) { if ($object instanceof entry && in_array(entryPeer::STATUS, $modifiedColumns) && ($object->getStatus() == entryStatus::READY || $object->getStatus() == entryStatus::ERROR_CONVERTING) && $object->getReplacedEntryId()) { kFlowHelper::handleEntryReplacement($object); return true; } if ($object instanceof UploadToken && in_array(UploadTokenPeer::STATUS, $modifiedColumns) && $object->getStatus() == UploadToken::UPLOAD_TOKEN_FULL_UPLOAD) { kFlowHelper::handleUploadFinished($object); return true; } if ($object instanceof BatchJob && $object->getJobType() == BatchJobType::BULKUPLOAD && $object->getStatus() == BatchJob::BATCHJOB_STATUS_ABORTED && in_array(BatchJobPeer::STATUS, $modifiedColumns) && in_array($object->getColumnsOldValue(BatchJobPeer::STATUS), BatchJobPeer::getClosedStatusList())) { $partner = $object->getPartner(); if ($partner->getEnableBulkUploadNotificationsEmails()) { kFlowHelper::sendBulkUploadNotificationEmail($object, MailType::MAIL_TYPE_BULKUPLOAD_ABORTED, array($partner->getAdminName(), $object->getId(), kFlowHelper::createBulkUploadLogUrl($object))); } return true; } if ($object instanceof UserRole && in_array(UserRolePeer::PERMISSION_NAMES, $modifiedColumns)) { $filter = new kuserFilter(); $filter->set('_eq_role_ids', $object->getId()); kJobsManager::addIndexJob($object->getPartnerId(), IndexObjectType::USER, $filter, false); return true; } if ($object instanceof FileSync) { $c = new Criteria(); $c->add(BatchJobLockPeer::OBJECT_ID, $object->getId()); $c->add(BatchJobLockPeer::OBJECT_TYPE, BatchJobObjectType::FILE_SYNC); $c->add(BatchJobLockPeer::JOB_TYPE, BatchJobType::FILESYNC_IMPORT); $c->add(BatchJobLockPeer::STATUS, array(BatchJob::BATCHJOB_STATUS_RETRY, BatchJob::BATCHJOB_STATUS_PENDING), Criteria::IN); $fileSyncImportJobs = BatchJobLockPeer::doSelect($c); foreach ($fileSyncImportJobs as $fileSyncImportJob) { kJobsManager::abortDbBatchJob(BatchJobPeer::retrieveByPK($fileSyncImportJob->getId())); } return true; } if (!$object instanceof flavorAsset || !in_array(assetPeer::STATUS, $modifiedColumns)) { return true; } $entry = entryPeer::retrieveByPKNoFilter($object->getEntryId()); KalturaLog::info("Asset id [" . $object->getId() . "] isOriginal [" . $object->getIsOriginal() . "] status [" . $object->getStatus() . "]"); if ($object->getIsOriginal()) { return true; } if ($object->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING) { $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR; $offset = $entry->getThumbOffset(); // entry getThumbOffset now takes the partner DefThumbOffset into consideration $syncKey = $object->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey, false); if (!$fileSync) { return true; } $srcFileSyncLocalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey); if ($srcFileSyncLocalPath) { kJobsManager::addPostConvertJob(null, $postConvertAssetType, $srcFileSyncLocalPath, $object->getId(), null, $entry->getCreateThumb(), $offset); } } elseif ($object->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { // If we get a ready flavor and the entry is in no content if ($entry->getStatus() == entryStatus::NO_CONTENT) { $entry->setStatus(entryStatus::PENDING); // we change the entry to pending $entry->save(); } } return true; }
/** * Selects a collection of BatchJob objects pre-filled with all related objects. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of BatchJob objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } BatchJobPeer::addSelectColumns($criteria); $startcol2 = BatchJobPeer::NUM_COLUMNS - BatchJobPeer::NUM_LAZY_LOAD_COLUMNS; BatchJobLockPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (BatchJobLockPeer::NUM_COLUMNS - BatchJobLockPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(BatchJobPeer::BATCH_JOB_LOCK_ID, BatchJobLockPeer::ID, $join_behavior); $stmt = BatchJobPeer::doSelectStmt($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = BatchJobPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = BatchJobPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = BatchJobPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); BatchJobPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined BatchJobLock rows $key2 = BatchJobLockPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = BatchJobLockPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = BatchJobLockPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); BatchJobLockPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (BatchJob) to the collection in $obj2 (BatchJobLock) $obj2->addBatchJob($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * * @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; }
/** * @return boolean */ public function isConvertingSegments() { $criteria = new Criteria(); $criteria->add(BatchJobLockPeer::PARTNER_ID, $this->getPartnerId()); $criteria->add(BatchJobLockPeer::ENTRY_ID, $this->getId()); $criteria->add(BatchJobLockPeer::JOB_TYPE, BatchJobType::CONVERT_LIVE_SEGMENT); $criteria->add(BatchJobLockPeer::DC, kDataCenterMgr::getCurrentDcId()); $batchJob = BatchJobLockPeer::doSelectOne($criteria); if ($batchJob) { return true; } return false; }
/** * 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; }
private static function unsuspendRootJob($jobIds) { if (empty($jobIds)) { return array(); } // Get possible root job ids // select root_job_id from batch_job_lock where id in (unsuspended jobs) $c = new Criteria(); $c->addSelectColumn(BatchJobLockPeer::ROOT_JOB_ID); $c->setDistinct(); $c->add(BatchJobLockPeer::ID, $jobIds, Criteria::IN); $stmt = BatchJobLockPeer::doSelectStmt($c); $rootIds = $stmt->fetchAll(PDO::FETCH_COLUMN); // Select only root ids that has no other suspended descendats $c = new Criteria(); $c->addSelectColumn(BatchJobLockSuspendPeer::ROOT_JOB_ID); $c->add(BatchJobLockSuspendPeer::ROOT_JOB_ID, $rootIds, Criteria::IN); $c->add(BatchJobLockSuspendPeer::ID, '(batch_job_lock_suspend.ID != batch_job_lock_suspend.ROOT_JOB_ID)', Criteria::CUSTOM); $c->addGroupByColumn(BatchJobLockSuspendPeer::ROOT_JOB_ID); $c->addHaving($c->getNewCriterion(BatchJobLockSuspendPeer::ROOT_JOB_ID, 'COUNT(batch_job_lock_suspend.ID)>0', Criteria::CUSTOM)); $stmt = BatchJobLockSuspendPeer::doSelectStmt($c); $usedRootIds = $stmt->fetchAll(PDO::FETCH_COLUMN); $unsuspendedRootJobs = array_diff($rootIds, $usedRootIds); self::moveFromSuspendedJobsTable($unsuspendedRootJobs); return $unsuspendedRootJobs; }
private static function commonLockObjectUpdate(BatchJob $batchJob, BatchJobLock $batchJobLock) { $jobType = $batchJob->getJobType(); $batchJobLock->setStatus($batchJob->getStatus()); $batchJobLock->setObjectId($batchJob->getObjectId()); $batchJobLock->setObjectType($batchJob->getObjectType()); if ($batchJob->getStatus() == BatchJob::BATCHJOB_STATUS_RETRY || $batchJob->getStatus() == BatchJob::BATCHJOB_STATUS_ALMOST_DONE) { $batchJobLock->setStartAt(time() + BatchJobLockPeer::getRetryInterval($jobType)); } if ($batchJob->getLockInfo() != null) { $batchJobLock->setPriority($batchJob->getLockInfo()->getPriority()); $batchJobLock->setUrgency($batchJob->getLockInfo()->getUrgency()); $batchJobLock->setEstimatedEffort($batchJob->getLockInfo()->getEstimatedEffort()); $batchJobLock->setVersion($batchJob->getLockInfo()->getLockVersion()); } }