protected function provision(KalturaBatchJob $job, KalturaProvisionJobData $data)
 {
     $job = $this->updateJob($job, null, KalturaBatchJobStatus::QUEUED);
     $engine = KProvisionEngine::getInstance($job->jobSubType, $data);
     if ($engine == null) {
         $err = "Cannot find provision engine [{$job->jobSubType}] for job id [{$job->id}]";
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::ENGINE_NOT_FOUND, $err, KalturaBatchJobStatus::FAILED);
     }
     KalturaLog::info("Using engine: " . $engine->getName());
     $results = $engine->provide($job, $data);
     if ($results->status == KalturaBatchJobStatus::FINISHED) {
         return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::ALMOST_DONE, $results->data);
     }
     return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, null, $results->errMessage, $results->status, $results->data);
 }
 protected function closeProvisionProvide(KalturaBatchJob $job)
 {
     if ($job->queueTime + self::$taskConfig->params->maxTimeBeforeFail < time()) {
         return new KProvisionEngineResult(KalturaBatchJobStatus::CLOSER_TIMEOUT, "Timed out");
     }
     $engine = KProvisionEngine::getInstance($job->jobSubType, $job->data);
     if ($engine == null) {
         $err = "Cannot find provision engine [{$job->jobSubType}] for job id [{$job->id}]";
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::ENGINE_NOT_FOUND, $err, KalturaBatchJobStatus::FAILED);
     }
     KalturaLog::info("Using engine: " . $engine->getName());
     $results = $engine->checkProvisionedStream($job, $job->data);
     if ($results->status == KalturaBatchJobStatus::FINISHED) {
         return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED, $results->data);
     }
     return $this->closeJob($job, null, null, $results->errMessage, KalturaBatchJobStatus::ALMOST_DONE, $results->data);
 }