コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function createJobExecution(JobInstance $jobInstance)
 {
     $jobExecution = new JobExecution();
     $jobExecution->setJobInstance($jobInstance);
     $this->updateJobExecution($jobExecution);
     return $jobExecution;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function updateJobExecution(JobExecution $jobExecution)
 {
     $uow = $this->getJobManager()->getUnitOfWork();
     $jobInstance = $jobExecution->getJobInstance();
     if ($jobInstance && UnitOfWork::STATE_DETACHED === $uow->getEntityState($jobInstance)) {
         /** @var JobInstance $jobInstance */
         $jobInstance = $uow->merge($jobInstance);
         $jobExecution->setJobInstance($jobInstance);
     }
     parent::updateJobExecution($jobExecution);
 }
コード例 #3
0
 protected function setUp()
 {
     $this->initClient();
     $this->loadFixtures(['OroCRM\\Bundle\\MagentoBundle\\Tests\\Functional\\Fixture\\LoadNewsletterSubscriberData']);
     $this->strategy = $this->getContainer()->get('orocrm_magento.import.strategy.newsletter_subscriber.add_or_update');
     $jobInstance = new JobInstance();
     $jobInstance->setRawConfiguration(['channel' => 3]);
     $jobExecution = new JobExecution();
     $jobExecution->setJobInstance($jobInstance);
     $this->stepExecution = new StepExecution('step', $jobExecution);
     $this->context = new StepExecutionProxyContext($this->stepExecution);
     $this->strategy->setImportExportContext($this->context);
     $this->strategy->setStepExecution($this->stepExecution);
 }
コード例 #4
0
 public function testHashArrayClearsOnWrite()
 {
     $jobExecution = new JobExecution();
     $jobExecution->setJobInstance(new JobInstance());
     $stepExecution = new StepExecution('step', $jobExecution);
     /** @var ContextRegistry $contextRegistry */
     $contextRegistry = $this->getContainer()->get('oro_importexport.context_registry');
     $context = $contextRegistry->getByStepExecution($stepExecution);
     $context->setValue(ProductPriceImportStrategy::PROCESSED_ENTITIES_HASH, [md5('hash1'), md5('hash2')]);
     $this->assertNotEmpty($context->getValue(ProductPriceImportStrategy::PROCESSED_ENTITIES_HASH));
     /** @var ProductPriceWriter $writer */
     $writer = $this->getContainer()->get('orob2b_pricing.importexport.writer.product_price');
     $writer->setStepExecution($stepExecution);
     $writer->write([]);
     $this->assertEmpty($context->getValue(ProductPriceImportStrategy::PROCESSED_ENTITIES_HASH));
 }
コード例 #5
0
 public function loadJobExecutions(ObjectManager $manager)
 {
     $handle = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'job_execution_data.csv', 'r');
     $headers = fgetcsv($handle, 1000, ',');
     while (($data = fgetcsv($handle, 1000, ',')) !== false) {
         $combined = array_combine($headers, $data);
         $createTime = new \DateTime('now', new \DateTimeZone('UTC'));
         $createTime->sub(\DateInterval::createFromDateString($combined['Create Time']));
         $jobExecutionEntity = new JobExecution();
         $jobExecutionEntity->setJobInstance($this->jobInstances[$combined['Job Instance']]);
         $jobExecutionEntity->setCreateTime($createTime);
         $jobExecutionEntity->setStatus(new BatchStatus($combined['Status']));
         $jobExecutionEntity->setPid($combined['Pid']);
         $manager->persist($jobExecutionEntity);
     }
     fclose($handle);
 }
コード例 #6
0
ファイル: JobExecutorTest.php プロジェクト: ramunasd/platform
 protected function setUp()
 {
     $this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $this->entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->managerRegistry = $this->getMockBuilder('Symfony\\Bridge\\Doctrine\\ManagerRegistry')->disableOriginalConstructor()->getMock();
     $this->batchJobRegistry = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Connector\\ConnectorRegistry')->disableOriginalConstructor()->getMock();
     $this->contextRegistry = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Context\\ContextRegistry')->disableOriginalConstructor()->getMock();
     $this->managerRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->entityManager));
     $this->batchJobManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->batchJobRepository = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Job\\DoctrineJobRepository')->disableOriginalConstructor()->getMock();
     $this->batchJobRepository->expects($this->any())->method('getJobManager')->will($this->returnValue($this->batchJobManager));
     $this->batchJobRepository->expects($this->any())->method('createJobExecution')->willReturnCallback(function ($instance) {
         $execution = new JobExecution();
         $execution->setJobInstance($instance);
         return $execution;
     });
     $this->executor = new JobExecutor($this->batchJobRegistry, $this->batchJobRepository, $this->contextRegistry, $this->managerRegistry);
 }
コード例 #7
0
ファイル: JobExecutor.php プロジェクト: xamin123/platform
 /**
  * @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;
 }
コード例 #8
0
 protected function expectGetJobName($stepExecution)
 {
     $jobInstance = new JobInstance(null, null, 'test');
     $jobExecution = new JobExecution();
     $jobExecution->setJobInstance($jobInstance);
     $executionContext = new ExecutionContext();
     $jobExecution->setExecutionContext($executionContext);
     $stepExecution->expects($this->once())->method('getJobExecution')->will($this->returnValue($jobExecution));
 }
コード例 #9
0
 /**
  * Launch a job
  *
  * @param Request $request
  * @param integer $id
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function launchAction(Request $request, $id)
 {
     try {
         $jobInstance = $this->getJobInstance($id);
     } catch (NotFoundHttpException $e) {
         $this->addFlash('error', $e->getMessage());
         return $this->redirectToIndexView();
     }
     $this->eventDispatcher->dispatch(JobProfileEvents::PRE_EXECUTE, new GenericEvent($jobInstance));
     $violations = $this->getValidator()->validate($jobInstance, array('Default', 'Execution'));
     $uploadViolations = $this->getValidator()->validate($jobInstance, array('Default', 'UploadExecution'));
     $uploadMode = $uploadViolations->count() === 0 ? $this->processUploadForm($jobInstance) : false;
     if ($uploadMode === true || $violations->count() === 0) {
         $jobExecution = new JobExecution();
         $jobExecution->setJobInstance($jobInstance);
         $this->persist($jobExecution);
         $instanceCode = $jobExecution->getJobInstance()->getCode();
         $executionId = $jobExecution->getId();
         $pathFinder = new PhpExecutableFinder();
         $cmd = sprintf('%s %s/console akeneo:batch:job --env=%s --email="%s" %s %s %s >> %s/logs/batch_execute.log 2>&1', $pathFinder->find(), $this->rootDir, $this->environment, $this->getUser()->getEmail(), $uploadMode ? sprintf('-c \'%s\'', json_encode($jobInstance->getJob()->getConfiguration())) : '', $instanceCode, $executionId, $this->rootDir);
         // Please note we do not use Symfony Process as it has some problem
         // when executed from HTTP request that stop fast (race condition that makes
         // the process cloning fail when the parent process, i.e. HTTP request, stops
         // at the same time)
         exec($cmd . ' &', $output);
         $this->eventDispatcher->dispatch(JobProfileEvents::POST_EXECUTE, new GenericEvent($jobInstance));
         $this->addFlash('success', sprintf('The %s is running.', $this->getJobType()));
         return $this->redirectToReportView($jobExecution->getId());
     }
     return $this->redirectToShowView($jobInstance->getId());
 }
 /**
  * {@inheritDoc}
  */
 public function setJobInstance(\Akeneo\Bundle\BatchBundle\Entity\JobInstance $jobInstance)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setJobInstance', array($jobInstance));
     return parent::setJobInstance($jobInstance);
 }