public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { // TODO - verify permissions for viewing lists $detailed = $this->getP("detailed", false); $limit = $this->getP("page_size", 10); $page = $this->getP("page", 1); //$order_by = int( $this->getP ( "order_by" , -1 ) ); $offset = ($page - 1) * $limit; $c = new Criteria(); $download_types = array(BatchJobType::FLATTEN, BatchJobType::DOWNLOAD); $c->add(BatchJobPeer::JOB_TYPE, $download_types, Criteria::IN); // filter $filter = new BatchJobFilter(true); $fields_set = $filter->fillObjectFromRequest($this->getInputParams(), "filter_", null); $filter->attachToCriteria($c); //if ($order_by != -1) kshowPeer::setOrder( $c , $order_by ); $count = BatchJobPeer::doCount($c); $offset = ($page - 1) * $limit; $c->setLimit($limit); if ($offset > 0) { $c->setOffset($offset); } $list = BatchJobPeer::doSelect($c); $level = objectWrapperBase::DETAIL_LEVEL_REGULAR; $this->addMsg("count", $count); $this->addMsg("page_size", $limit); $this->addMsg("page", $page); $wrapper = objectWrapperBase::getWrapperClass($list, $level); $this->addMsg("downloads", $wrapper); }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $limit = $this->getP("page_size", 20); $limit = min($limit, 100); $page = $this->getP("page", 1); $offset = ($page - 1) * $limit; $c = new Criteria(); $c->addAnd(BatchJobPeer::PARTNER_ID, $partner_id); $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD); $c->addDescendingOrderByColumn(BatchJobPeer::ID); $count = BatchJobPeer::doCount($c); $c->setLimit($limit); $c->setOffset($offset); $jobs = BatchJobPeer::doSelect($c); $obj = array(); foreach ($jobs as $job) { $jobData = $job->getData(); if (!$jobData instanceof kBulkUploadJobData) { continue; } $bulkResults = BulkUploadResultPeer::retrieveWithEntryByBulkUploadId($job->getId()); $obj[] = array("uploadedBy" => $jobData->getUploadedBy(), "uploadedOn" => $job->getCreatedAt(null), "numOfEntries" => count($bulkResults), "status" => $job->getStatus(), "error" => $job->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED ? $job->getMessage() : '', "logFileUrl" => requestUtils::getCdnHost() . "/index.php/extwidget/bulkuploadfile/id/{$job->getId()}/pid/{$job->getPartnerId()}/type/log", "csvFileUrl" => requestUtils::getCdnHost() . "/index.php/extwidget/bulkuploadfile/id/{$job->getId()}/pid/{$job->getPartnerId()}/type/csv"); } $this->addMsg("count", $count); $this->addMsg("page_size", $limit); $this->addMsg("page", $page); $this->addMsg("bulk_uploads", $obj); }
$flavorParamsArr = null; if (!is_null($flavorParamsIds) && strlen(trim($flavorParamsIds))) { $flavorParamsArr = explode(',', $flavorParamsIds); } $moreEntries = true; $maxConcurrentJobs = 20; $totalExported = 0; $lastCreatedAt = null; $processedIds = array(); $nonFinalBatchStatuses = array(BatchJob::BATCHJOB_STATUS_PENDING, BatchJob::BATCHJOB_STATUS_QUEUED, BatchJob::BATCHJOB_STATUS_PROCESSING, BatchJob::BATCHJOB_STATUS_PROCESSED, BatchJob::BATCHJOB_STATUS_MOVEFILE); while ($moreEntries) { $c = new Criteria(); $c->addAnd(BatchJobPeer::PARTNER_ID, $partnerId); $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::STORAGE_EXPORT); $c->addAnd(BatchJobPeer::STATUS, $nonFinalBatchStatuses, Criteria::IN); $batchCount = BatchJobPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL3)); if ($batchCount >= $maxConcurrentJobs) { sleep(30); continue; } $curLimit = $maxConcurrentJobs - $batchCount; $currentExported = 0; $c = new Criteria(); $c->add(entryPeer::PARTNER_ID, $partnerId); if ($lastCreatedAt) { $c->addAnd(entryPeer::CREATED_AT, $lastCreatedAt, Criteria::LESS_EQUAL); } $c->addDescendingOrderByColumn(entryPeer::CREATED_AT); $c->setLimit($curLimit); $entries = entryPeer::doSelect($c, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL3)); foreach ($entries as $entry) {
/** * 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->fromObject($job); // gets queues length $c = new Criteria(); $c->add(BatchJobPeer::STATUS, array(KalturaBatchJobStatus::PENDING, KalturaBatchJobStatus::RETRY, KalturaBatchJobStatus::ALMOST_DONE), Criteria::IN); $c->add(BatchJobPeer::JOB_TYPE, $jobType); $queueSize = BatchJobPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2)); if (!$queueSize) { // gets queues length $c = new Criteria(); $c->add(BatchJobPeer::BATCH_INDEX, null, Criteria::ISNOTNULL); $c->add(BatchJobPeer::PROCESSOR_EXPIRATION, time(), Criteria::GREATER_THAN); $c->add(BatchJobPeer::EXECUTION_ATTEMPTS, BatchJobPeer::getMaxExecutionAttempts($jobType), Criteria::LESS_THAN); $c->add(BatchJobPeer::JOB_TYPE, $jobType); $queueSize = BatchJobPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2)); } $response = new KalturaFreeJobResponse(); $response->job = $batchJob; $response->jobType = $jobType; $response->queueSize = $queueSize; return $response; }
/** * list Batch Jobs * * @action listBatchJobs * @param KalturaBatchJobFilter $filter * @param KalturaFilterPager $pager * @return KalturaBatchJobListResponse */ function listBatchJobsAction(KalturaBatchJobFilter $filter = null, KalturaFilterPager $pager = null) { if (!$filter) { $filter = new KalturaBatchJobFilter(); } $batchJobFilter = new BatchJobFilter(); $filter->toObject($batchJobFilter); $c = new Criteria(); // $c->add(BatchJobPeer::DELETED_AT, null); $batchJobFilter->attachToCriteria($c); if (!$pager) { $pager = new KalturaFilterPager(); } $pager->attachToCriteria($c); myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2; $list = BatchJobPeer::doSelect($c); $c->setLimit(false); $count = BatchJobPeer::doCount($c); $newList = KalturaBatchJobArray::fromStatisticsBatchJobArray($list); $response = new KalturaBatchJobListResponse(); $response->objects = $newList; $response->totalCount = $count; return $response; }
/** * Returns the number of related BatchJob objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related BatchJob objects. * @throws PropelException */ public function countBatchJobs(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(BatchJobLockPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collBatchJobs === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(BatchJobPeer::BATCH_JOB_LOCK_ID, $this->id); $count = BatchJobPeer::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(BatchJobPeer::BATCH_JOB_LOCK_ID, $this->id); if (!isset($this->lastBatchJobCriteria) || !$this->lastBatchJobCriteria->equals($criteria)) { $count = BatchJobPeer::doCount($criteria, false, $con); } else { $count = count($this->collBatchJobs); } } else { $count = count($this->collBatchJobs); } } return $count; }
private static function getQueue(Criteria $c, $schedulerId, $workerId, $max_exe_attempts) { $schd = BatchJobPeer::SCHEDULER_ID; $work = BatchJobPeer::WORKER_ID; $stat = BatchJobPeer::STATUS; $atmp = BatchJobPeer::EXECUTION_ATTEMPTS; $expr = BatchJobPeer::PROCESSOR_EXPIRATION; $recheck = BatchJobPeer::CHECK_AGAIN_TIMEOUT; $schd_id = $schedulerId; $work_id = $workerId; $now = time(); $now_str = date('Y-m-d H:i:s', $now); // same workers unfinished jobs $query1 = "(\r\n\t\t\t\t\t\t\t{$schd} = {$schd_id} \r\n\t\t\t\t\t\tAND {$work} = {$work_id} \r\n\t\t\t\t\t\tAND {$stat} IN (" . BatchJobPeer::getInProcStatusList() . ") \r\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 $closedStatuses = implode(',', BatchJobPeer::getClosedStatusList()); $query2 = "(\r\n\t\t\t\t\t\t\t{$stat} NOT IN ({$closedStatuses})\r\n\t\t\t\t\t\tAND\t{$expr} <= '{$now_str}'\r\n\t\t\t\t\t)"; // "retry jobs" $query3 = "(\r\n\t\t\t\t\t\t{$stat} = " . BatchJob::BATCHJOB_STATUS_RETRY . "\r\n\t\t\t\t\t\tAND {$recheck} <= {$now}\r\n\t\t\t\t\t)"; // "max attempts jobs" $queryMaxAttempts = "(\r\n\t\t\t\t\t\t\t\t{$atmp} <= {$max_exe_attempts}\r\n\t\t\t\t\t\t\t\tOR\r\n\t\t\t\t\t\t\t\t{$atmp} IS NULL\r\n\t\t\t\t\t\t\t)"; $crit1 = $c->getNewCriterion($stat, BatchJob::BATCHJOB_STATUS_PENDING); $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(BatchJobPeer::DC, kDataCenterMgr::getCurrentDcId())); // $objects = BatchJobPeer::doCount ( $c ); return BatchJobPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2)); }
/** * List bulk upload batch jobs * * @action list * @param KalturaFilterPager $pager * @return KalturaBulkUploadListResponse */ function listAction(KalturaFilterPager $pager = null) { if (!$pager) { $pager = new KalturaFilterPager(); } $c = new Criteria(); $c->addAnd(BatchJobPeer::PARTNER_ID, $this->getPartnerId()); $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD); $c->addDescendingOrderByColumn(BatchJobPeer::ID); $count = BatchJobPeer::doCount($c); $pager->attachToCriteria($c); $jobs = BatchJobPeer::doSelect($c); $response = new KalturaBulkUploadListResponse(); $response->objects = KalturaBulkUploads::fromBatchJobArray($jobs); $response->totalCount = $count; return $response; }