private static function lockObjects(kExclusiveLockKey $lockKey, array $objects, $max_execution_time) { $exclusive_objects_ids = array(); // make sure the objects where not taken - $con = Propel::getConnection(); $not_exclusive_count = 0; foreach ($objects as $object) { $lock_version = $object->getVersion(); $criteria_for_exclusive_update = new Criteria(); $criteria_for_exclusive_update->add(BatchJobLockPeer::ID, $object->getId()); $criteria_for_exclusive_update->add(BatchJobLockPeer::VERSION, $lock_version); $update = new Criteria(); // increment the lock_version - this will make sure it's exclusive $update->add(BatchJobLockPeer::VERSION, $lock_version + 1); // increment the execution_attempts $update->add(BatchJobLockPeer::EXECUTION_ATTEMPTS, $object->getExecutionAttempts() + 1); $update->add(BatchJobLockPeer::SCHEDULER_ID, $lockKey->getSchedulerId()); $update->add(BatchJobLockPeer::WORKER_ID, $lockKey->getWorkerId()); $update->add(BatchJobLockPeer::BATCH_INDEX, $lockKey->getBatchIndex()); $expiration = time() + $max_execution_time; $update->add(BatchJobLockPeer::EXPIRATION, $expiration); $affectedRows = BasePeer::doUpdate($criteria_for_exclusive_update, $update, $con); KalturaLog::log("Lock update affected rows [{$affectedRows}] on job id [" . $object->getId() . "] lock version [{$lock_version}]"); if ($affectedRows == 1) { // fix the object to reflect what is in the DB $object->setVersion($lock_version + 1); $object->setExecutionAttempts($object->getExecutionAttempts() + 1); $object->setSchedulerId($lockKey->getSchedulerId()); $object->setWorkerId($lockKey->getWorkerId()); $object->setBatchIndex($lockKey->getBatchIndex()); $object->setExpiration($expiration); KalturaLog::log("Job id [" . $object->getId() . "] locked and returned"); PartnerLoadPeer::updatePartnerLoad($object->getPartnerId(), $object->getJobType(), $object->getJobSubType(), $con); $exclusive_objects_ids[] = $object->getId(); } else { $not_exclusive_count++; KalturaLog::log("Object not exclusive: [" . get_class($object) . "] id [" . $object->getId() . "]"); } } return BatchJobPeer::postLockUpdate($lockKey, $exclusive_objects_ids, $con); }
public static function updatePartnerLoadTable() { $actualPartnerLoads = PartnerLoadPeer::getPartnerLoads(); $c = new Criteria(); $c->add(PartnerLoadPeer::DC, kDataCenterMgr::getCurrentDcId()); $currentPartnerLoads = PartnerLoadPeer::doSelect($c); // This loop updates the partner load table contents according to the // accurate information gathered from the batch job table foreach ($currentPartnerLoads as $partnerLoad) { $maxQuota = self::getMaxQuotaForPartner($partnerLoad); $key = $partnerLoad->getPartnerId() . "#" . $partnerLoad->getJobType() . "#" . $partnerLoad->getJobSubType(); if (array_key_exists($key, $actualPartnerLoads)) { $actualLoad = $actualPartnerLoads[$key]; // Update $partnerLoad->setPartnerLoad($actualLoad->getPartnerLoad()); $partnerLoad->setWeightedPartnerLoad($actualLoad->getWeightedPartnerLoad()); $partnerLoad->setQuota($maxQuota - $actualLoad->getPartnerLoad()); $partnerLoad->save(); unset($actualPartnerLoads[$key]); } else { // Delete $partnerLoad->delete(); } } foreach ($actualPartnerLoads as $actualPartnerLoad) { $maxQuota = self::getMaxQuotaForPartner($actualPartnerLoad); $actualPartnerLoad->setQuota($maxQuota - $actualPartnerLoad->getPartnerLoad()); $actualPartnerLoad->save(); } }
/** * batch updatePartnerLoadTable action cleans the partner load table * * @action updatePartnerLoadTable */ function updatePartnerLoadTableAction() { KalturaResponseCacher::disableCache(); PartnerLoadPeer::updatePartnerLoadTable(); }
/** * Retrieve object using using composite pkey values. * @param int $job_type * @param int $job_sub_type * @param int $partner_id * @param int $dc * @param PropelPDO $con * @return PartnerLoad */ public static function retrieveByPK($job_type, $job_sub_type, $partner_id, $dc, PropelPDO $con = null) { $key = serialize(array((string) $job_type, (string) $job_sub_type, (string) $partner_id, (string) $dc)); if (null !== ($obj = PartnerLoadPeer::getInstanceFromPool($key))) { return $obj; } $criteria = new Criteria(PartnerLoadPeer::DATABASE_NAME); $criteria->add(PartnerLoadPeer::JOB_TYPE, $job_type); $criteria->add(PartnerLoadPeer::JOB_SUB_TYPE, $job_sub_type); $criteria->add(PartnerLoadPeer::PARTNER_ID, $partner_id); $criteria->add(PartnerLoadPeer::DC, $dc); $v = PartnerLoadPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
/** * 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 = PartnerLoadPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setJobType($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setJobSubType($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setPartnerId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setDc($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setPartnerLoad($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setWeightedPartnerLoad($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setQuota($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setCustomData($arr[$keys[7]]); } }