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 static function getExpiredJobs() { $jobTypes = kPluginableEnumsManager::coreValues('BatchJobType'); $executionAttempts2jobTypes = array(); // Map between max execution attempts and job types foreach ($jobTypes as $jobType) { $executionAttempts = BatchJobLockPeer::getMaxExecutionAttempts($jobType); if (array_key_exists($executionAttempts, $executionAttempts2jobTypes)) { $executionAttempts2jobTypes[$executionAttempts][] = $jobType; } else { $executionAttempts2jobTypes[$executionAttempts] = array($jobType); } } // create query $c = new Criteria(); $c->add(BatchJobLockPeer::STATUS, BatchJob::BATCHJOB_STATUS_FATAL, Criteria::NOT_EQUAL); $c->add(BatchJobLockPeer::DC, kDataCenterMgr::getCurrentDcId()); // each DC should clean its own jobs // Query for each job type $batchJobLocks = array(); foreach ($executionAttempts2jobTypes as $execAttempts => $jobTypes) { $typedCrit = clone $c; $typedCrit->add(BatchJobLockPeer::EXECUTION_ATTEMPTS, $execAttempts, Criteria::GREATER_THAN); $typedCrit->add(BatchJobLockPeer::JOB_TYPE, $jobTypes, Criteria::IN); $typedJobs = BatchJobLockPeer::doSelect($typedCrit, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2)); foreach ($typedJobs as $typedJob) { $batchJobLocks[$typedJob->getId()] = $typedJob; } } // get matching batch jobs return BatchJobPeer::retrieveByPKs(array_keys($batchJobLocks)); }
/** * Gets an array of BatchJobLock objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this BatchJob has previously been saved, it will retrieve * related BatchJobLocks from storage. If this BatchJob is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array BatchJobLock[] * @throws PropelException */ public function getBatchJobLocks($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(BatchJobPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collBatchJobLocks === null) { if ($this->isNew()) { $this->collBatchJobLocks = array(); } else { $criteria->add(BatchJobLockPeer::BATCH_JOB_ID, $this->id); BatchJobLockPeer::addSelectColumns($criteria); $this->collBatchJobLocks = BatchJobLockPeer::doSelect($criteria, $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 the collection. $criteria->add(BatchJobLockPeer::BATCH_JOB_ID, $this->id); BatchJobLockPeer::addSelectColumns($criteria); if (!isset($this->lastBatchJobLockCriteria) || !$this->lastBatchJobLockCriteria->equals($criteria)) { $this->collBatchJobLocks = BatchJobLockPeer::doSelect($criteria, $con); } } } $this->lastBatchJobLockCriteria = $criteria; return $this->collBatchJobLocks; }
$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; }
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; }
/** * 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; }