/** * {@inheritdoc} * * @return JobInstance */ protected function createEntity(array $data) { $job = new JobInstance($data['connector'], $data['type'], 'alias'); $job->setCode($data['code']); $job->setLabel($data['label']); return $job; }
/** * @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; }
/** * @param TableNode $table * * @Given /^the following jobs?:$/ */ public function theFollowingJobs(TableNode $table) { $registry = $this->getContainer()->get('akeneo_batch.connectors'); foreach ($table->getHash() as $data) { $jobInstance = new JobInstance($data['connector'], $data['type'], $data['alias']); $jobInstance->setCode($data['code']); $jobInstance->setLabel($data['label']); $job = $registry->getJob($jobInstance); $jobInstance->setJob($job); $this->validate($jobInstance); $this->persist($jobInstance); } }
/** * Create and persist job instance. * * @param string $jobType * @param string $jobName * @param array $configuration * @return JobInstance */ protected function createJobInstance($jobType, $jobName, array $configuration) { $jobInstance = new JobInstance(self::CONNECTOR_NAME, $jobType, $jobName); $jobInstance->setCode($this->generateJobCode($jobName)); $jobInstance->setLabel(sprintf('%s.%s', $jobType, $jobName)); if (array_key_exists(self::JOB_CONTEXT_DATA_KEY, $configuration)) { unset($configuration[self::JOB_CONTEXT_DATA_KEY]); } $jobInstance->setRawConfiguration($configuration); $this->batchJobRepository->getJobManager()->persist($jobInstance); return $jobInstance; }
/** * {@inheritDoc} */ public function setLabel($label) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setLabel', array($label)); return parent::setLabel($label); }