public function dispatch(KalturaEventNotificationTemplate $eventNotificationTemplate, KalturaEventNotificationDispatchJobData &$data)
 {
     $job = KJobHandlerWorker::getCurrentJob();
     $variables = array();
     if (is_array($data->contentParameters) && count($data->contentParameters)) {
         foreach ($data->contentParameters as $contentParameter) {
             /* @var $contentParameter KalturaKeyValue */
             $variables[$contentParameter->key] = $contentParameter->value;
         }
     }
     switch ($job->jobSubType) {
         case KalturaEventNotificationTemplateType::BPM_START:
             return $this->startBusinessProcess($eventNotificationTemplate, $data, $variables);
         case KalturaEventNotificationTemplateType::BPM_SIGNAL:
             return $this->signalCase($eventNotificationTemplate, $data, $variables);
         case KalturaEventNotificationTemplateType::BPM_ABORT:
             return $this->abortCase($eventNotificationTemplate, $data);
     }
 }
 public function doRecalculate(KalturaRecalculateResponseProfileCacheJobData $data)
 {
     $job = KJobHandlerWorker::getCurrentJob();
     KBatchBase::impersonate($job->partnerId);
     $partner = KBatchBase::$kClient->partner->get($job->partnerId);
     KBatchBase::unimpersonate();
     $role = reset($data->userRoles);
     /* @var $role KalturaIntegerValue */
     $privileges = array('setrole:' . $role->value, 'disableentitlement');
     $privileges = implode(',', $privileges);
     $client = new KalturaClient(KBatchBase::$kClientConfig);
     $ks = $client->generateSession($partner->adminSecret, 'batchUser', $data->ksType, $job->partnerId, 86400, $privileges);
     $client->setKs($ks);
     $options = new KalturaResponseProfileCacheRecalculateOptions();
     $options->limit = $this->maxCacheObjectsPerRequest;
     $options->cachedObjectType = $data->cachedObjectType;
     $options->objectId = $data->objectId;
     $options->startObjectKey = $data->startObjectKey;
     $options->endObjectKey = $data->endObjectKey;
     $options->jobCreatedAt = $job->createdAt;
     $options->isFirstLoop = true;
     $recalculated = 0;
     try {
         do {
             $results = $client->responseProfile->recalculate($options);
             $recalculated += $results->recalculated;
             $options->startObjectKey = $results->lastObjectKey;
             $options->isFirstLoop = false;
         } while ($results->lastObjectKey);
     } catch (KalturaException $e) {
         if ($e->getCode() != self::RESPONSE_PROFILE_CACHE_ALREADY_RECALCULATED && $e->getCode() != self::RESPONSE_PROFILE_CACHE_RECALCULATE_RESTARTED) {
             throw $e;
         }
         KalturaLog::err($e);
     }
     return $recalculated;
 }
 protected function getNotificationUrl(KalturaUnicornDistributionJobProviderData $providerData)
 {
     $job = KJobHandlerWorker::getCurrentJob();
     $serviceUrl = trim($providerData->notificationBaseUrl, '/');
     return "{$serviceUrl}/api_v3/index.php/service/unicornDistribution_unicorn/action/notify/partnerId/{$job->partnerId}/id/{$job->id}";
 }