Exemple #1
0
 /**
  * @param string $jobType
  * @param string $jobName
  * @param array $configuration
  * @return JobResult
  */
 public function executeJob($jobType, $jobName, array $configuration = array())
 {
     // create and persist job instance and job execution
     $jobInstance = new JobInstance(self::CONNECTOR_NAME, $jobType, $jobName);
     $jobInstance->setCode($this->generateJobCode($jobName));
     $jobInstance->setLabel(sprintf('%s.%s', $jobType, $jobName));
     $jobInstance->setRawConfiguration($configuration);
     $jobExecution = new JobExecution();
     $jobExecution->setJobInstance($jobInstance);
     // persist batch entities
     $this->batchJobManager->persist($jobInstance);
     $this->batchJobManager->persist($jobExecution);
     // do job
     $jobResult = $this->doJob($jobInstance, $jobExecution);
     // EntityManager can be closed when there was an exception in flush method called inside some jobs execution
     // Can't be implemented right now due to OroEntityManager external dependencies
     // on ExtendManager and FilterCollection
     if (!$this->entityManager->isOpen()) {
         $this->managerRegistry->resetManager();
         $this->entityManager = $this->managerRegistry->getManager();
     }
     // flush batch entities
     $this->batchJobManager->flush($jobInstance);
     $this->batchJobManager->flush($jobExecution);
     // set data to JobResult
     $jobResult->setJobId($jobInstance->getId());
     $jobResult->setJobCode($jobInstance->getCode());
     // TODO: Find a way to work with multiple amount of job and step executions
     // TODO: https://magecore.atlassian.net/browse/BAP-2600
     /** @var JobExecution $jobExecution */
     $jobExecution = $jobInstance->getJobExecutions()->first();
     if ($jobExecution) {
         $stepExecution = $jobExecution->getStepExecutions()->first();
         if ($stepExecution) {
             $context = $this->contextRegistry->getByStepExecution($stepExecution);
             $jobResult->setContext($context);
         }
     }
     return $jobResult;
 }