/**
  * 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;
 }