/**
  * 
  * Starts the bulk upload
  * @param KalturaBatchJob $job
  */
 private function startBulkUpload(KalturaBatchJob $job)
 {
     KalturaLog::info("Start bulk upload ({$job->id})");
     //Gets the right Engine instance
     $engine = KBulkUploadEngine::getEngine($job->jobSubType, $job);
     if (is_null($engine)) {
         throw new KalturaException("Unable to find bulk upload engine", KalturaBatchJobAppErrors::ENGINE_NOT_FOUND);
     }
     $job = $this->updateJob($job, 'Parsing file [' . $engine->getName() . ']', KalturaBatchJobStatus::QUEUED, $engine->getData());
     $engine->setJob($job);
     $engine->setData($job->data);
     $engine->handleBulkUpload();
     $job = $engine->getJob();
     $data = $engine->getData();
     $countObjects = $this->countCreatedObjects($job->id, $job->data->bulkUploadObjectType);
     $countHandledObjects = $countObjects[0];
     $countErrorObjects = $countObjects[1];
     if (!$countHandledObjects && !$engine->shouldRetry() && $countErrorObjects) {
         throw new KalturaBatchException("None of the uploaded items were processed succsessfuly", KalturaBatchJobAppErrors::BULK_NO_ENTRIES_HANDLED, $engine->getData());
     }
     if ($engine->shouldRetry()) {
         self::$kClient->batch->resetJobExecutionAttempts($job->id, $this->getExclusiveLockKey(), $job->jobType);
         return $this->closeJob($job, null, null, "Retrying: " . $countHandledObjects . " " . $engine->getObjectTypeTitle() . " objects were handled untill now", KalturaBatchJobStatus::RETRY);
     }
     return $this->closeJob($job, null, null, 'Waiting for objects closure', KalturaBatchJobStatus::ALMOST_DONE, $data);
 }
 /**
  * 
  * Starts the bulk upload
  * @param KalturaBatchJob $job
  */
 private function startBulkUpload(KalturaBatchJob $job)
 {
     KalturaLog::debug("startBulkUpload({$job->id})");
     //Gets the right Engine instance
     $engine = KBulkUploadEngine::getEngine($job->jobSubType, $this->taskConfig, $this->kClient, $job);
     if (is_null($engine)) {
         throw new KalturaException("Unable to find bulk upload engine", KalturaBatchJobAppErrors::ENGINE_NOT_FOUND);
     }
     $this->updateJob($job, 'Parsing file [' . $engine->getName() . ']', KalturaBatchJobStatus::QUEUED, 1);
     $openedEntries = $this->kClient->batch->updateBulkUploadResults($job->id);
     if ($openedEntries) {
         KalturaLog::debug("There are open objects on the job so we wait for them");
         $this->kClient->batch->resetJobExecutionAttempts($job->id, $this->getExclusiveLockKey(), $job->jobType);
         return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::RETRY);
     }
     $engine->handleBulkUpload();
     $job = $engine->getJob();
     $data = $engine->getData();
     $countHandledObjects = $this->countCreatedObjects($job->id, $job->data->bulkUploadObjectType);
     if (!$countHandledObjects) {
         throw new KalturaBatchException("None of the uploaded items were processed succsessfuly", KalturaBatchJobAppErrors::BULK_NO_ENTRIES_HANDLED);
     }
     if ($engine->shouldRetry()) {
         $handledObjectsTypeName = $this->getBulkUploadObectTypeName($job->data->bulkUploadObjectType);
         KalturaLog::debug("Set the job to retry");
         $this->kClient->batch->resetJobExecutionAttempts($job->id, $this->getExclusiveLockKey(), $job->jobType);
         return $this->closeJob($job, null, null, "Retrying: [{$countHandledObjects}] {$handledObjectsTypeName} objects were handled untill now", KalturaBatchJobStatus::RETRY);
     }
     return $this->closeJob($job, null, null, 'Waiting for objects closure', KalturaBatchJobStatus::ALMOST_DONE, $data);
 }