/** * @param KalturaScheduledTaskProfile $profile */ protected function processProfile(KalturaScheduledTaskProfile $profile) { $this->updateProfileBeforeExecution($profile); if ($profile->maxTotalCountAllowed) { $maxTotalCountAllowed = $profile->maxTotalCountAllowed; } else { $maxTotalCountAllowed = $this->getParams('maxTotalCountAllowed'); } $pager = new KalturaFilterPager(); $pager->pageIndex = 1; $pager->pageSize = 500; while (true) { $this->impersonate($profile->partnerId); try { $result = ScheduledTaskBatchHelper::query($this->getClient(), $profile, $pager); $this->unimpersonate(); } catch (Exception $ex) { $this->unimpersonate(); throw $ex; } if ($result->totalCount > $maxTotalCountAllowed) { KalturaLog::crit("List query for profile {$profile->id} returned too many results ({$result->totalCount} when the allowed total count is {$maxTotalCountAllowed}), suspending the profile"); $this->suspendProfile($profile); break; } if (!count($result->objects)) { break; } foreach ($result->objects as $object) { $this->processObject($profile, $object); } $pager->pageIndex++; } }
public function exec(KalturaBatchJob $job) { $sharedPath = $this->getAdditionalParams('sharedTempPath'); if (!is_dir($sharedPath)) { kFile::fullMkfileDir($sharedPath); if (!is_dir($sharedPath)) { throw new Exception('Shared path [' . $sharedPath . '] doesn\'t exist and could not be created'); } } KalturaLog::debug('Temp shared path: ' . $sharedPath); /** @var KalturaScheduledTaskJobData $jobData */ $jobData = $job->data; $profileId = $job->jobObjectId; $maxResults = $jobData->maxResults ? $jobData->maxResults : 500; $scheduledTaskClient = $this->getScheduledTaskClient(); $scheduledTaskProfile = $scheduledTaskClient->scheduledTaskProfile->get($profileId); $pager = new KalturaFilterPager(); $pager->pageSize = 500; $pager->pageIndex = 1; $response = new KalturaObjectListResponse(); $response->objects = array(); $response->totalCount = 0; $resultsCount = 0; while (true) { $client = $this->getClient(); $ks = $this->createKs($client, $jobData); $client->setKs($ks); $this->impersonate($scheduledTaskProfile->partnerId); try { $results = ScheduledTaskBatchHelper::query($client, $scheduledTaskProfile, $pager); $this->unimpersonate(); } catch (Exception $ex) { $this->unimpersonate(); throw $ex; } if (!count($results->objects)) { break; } $resultsCount += count($results->objects); if ($resultsCount >= $maxResults) { break; } $response->objects = array_merge($response->objects, $results->objects); $response->totalCount += count($results->objects); $pager->pageIndex++; } $sharedFilePath = $sharedPath . '/' . uniqid('sheduledtask_'); KalturaLog::debug('Temp shared file: ' . $sharedFilePath); file_put_contents($sharedFilePath, serialize($response)); $jobData->resultsFilePath = $sharedFilePath; return $this->closeJob($job, null, null, 'Dry run finished', KalturaBatchJobStatus::FINISHED, $jobData); }