/** * {@inheritdoc} */ public function createJobExecution(JobInstance $jobInstance) { $jobExecution = new JobExecution(); $jobExecution->setJobInstance($jobInstance); $this->updateJobExecution($jobExecution); return $jobExecution; }
function it_throws_exception_when_serializer_is_not_a_normalizer(JobExecution $jobExecution, SerializerInterface $nonNormalizeSerializer, $exportExecution, $cleanExecution) { $this->setSerializer($nonNormalizeSerializer); $jobExecution->getStepExecutions()->willReturn([$exportExecution, $cleanExecution]); $jobExecution->getFailureExceptions()->willReturn([]); $jobExecution->getLabel()->willReturn('My Job'); $this->shouldThrow(new \RuntimeException('Cannot normalize job execution of "My Job" because injected serializer is not a normalizer'))->duringNormalize($jobExecution, 'any'); }
/** * {@inheritdoc} */ public function supports(JobExecution $jobExecution) { foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) { if ($step instanceof ItemStep && $this->isUsableWriter($step->getWriter())) { return true; } } return false; }
function it_returns_generated_archives(JobExecution $jobExecution, ArchiverInterface $archiver, ArchiverInterface $archiver2) { $jobExecution->isRunning()->willReturn(false); $archiver->getName()->willReturn('output'); $archiver->getArchives($jobExecution)->willReturn(['a', 'b']); $this->registerArchiver($archiver); $archiver2->getName()->willReturn('input'); $archiver2->getArchives($jobExecution)->willReturn(['a', 'b']); $this->registerArchiver($archiver2); $this->getArchives($jobExecution)->shouldReturn(['output' => ['a', 'b'], 'input' => ['a', 'b']]); }
/** * {@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); }
public function testExecuteStoppingWithNoStep() { $jobInstance = new JobInstance('test_connector', JobInstance::TYPE_IMPORT, 'test_job_instance'); $jobExecution = new JobExecution($jobInstance); $jobExecution->setStatus(new BatchStatus(BatchStatus::STOPPING)); $this->job->setJobRepository($this->jobRepository); $this->job->execute($jobExecution); $this->assertNull($jobExecution->getStartTime()); $this->assertEquals(BatchStatus::STOPPED, $jobExecution->getStatus()->getValue(), 'Batch status stopped'); $this->assertEquals(ExitStatus::NOOP, $jobExecution->getExitStatus()->getExitCode(), 'Exit status completed'); }
function it_returns_false_for_the_unsupported_job(ItemReaderInterface $reader, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step) { $jobExecution->getJobInstance()->willReturn($jobInstance); $jobExecution->getId()->willReturn(12); $jobInstance->getJob()->willReturn($job); $jobInstance->getType()->willReturn('type'); $jobInstance->getAlias()->willReturn('alias'); $job->getSteps()->willReturn([$step]); $step->getReader()->willReturn($reader); $this->supports($jobExecution)->shouldReturn(false); }
/** * @param JobExecution $jobExecution */ public function __construct(JobExecution $jobExecution) { $message = ''; foreach ($jobExecution->getFailureExceptions() as $exception) { $message .= $this->getFailureExceptionMessage('JOB', $exception); } foreach ($jobExecution->getStepExecutions() as $stepExecution) { $message .= $this->getStepExecutionMessages($stepExecution); } parent::__construct($message); }
/** * Get the archives generated by the archivers * * @param JobExecution $jobExecution * * @return array */ public function getArchives(JobExecution $jobExecution) { $result = array(); if (!$jobExecution->isRunning()) { foreach ($this->archivers as $archiver) { if (count($archives = $archiver->getArchives($jobExecution)) > 0) { $result[$archiver->getName()] = $archives; } } } return $result; }
protected function setUp() { $this->transportMock = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Transport\\MagentoTransportInterface'); $this->stepExecutionMock = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->setMethods(['getExecutionContext', 'getJobExecution'])->disableOriginalConstructor()->getMock(); $this->executionContextMock = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext'); $this->jobExecutionMock = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution'); $this->jobExecutionMock->expects($this->any())->method('getExecutionContext')->will($this->returnValue($this->executionContextMock)); $this->stepExecutionMock->expects($this->any())->method('getJobExecution')->will($this->returnValue($this->jobExecutionMock)); $this->managerRegistryMock = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock(); $this->integrationRepositoryMock = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Repository\\ChannelRepository')->disableOriginalConstructor()->getMock(); $this->managerRegistryMock->expects($this->any())->method('getRepository')->with('OroIntegrationBundle:Channel')->will($this->returnValue($this->integrationRepositoryMock)); }
/** * Archive files used by job execution (input / output) * * @param JobExecution $jobExecution */ public function archive(JobExecution $jobExecution) { foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) { if (!$step instanceof ItemStep) { continue; } $reader = $step->getReader(); if ($reader instanceof FileIteratorReader) { $key = strtr($this->getRelativeArchivePath($jobExecution), ['%filename%' => basename($reader->getFilePath())]); $this->filesystem->put($key, file_get_contents($reader->getFilePath())); } } }
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); }
function it_archives_unvalid_items(InvalidItemsCollector $collector, CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Filesystem $filesystem) { $collector->getInvalidItems()->willReturn(['items']); $jobExecution->getId()->willReturn('id'); $jobExecution->getJobInstance()->willReturn($jobInstance); $jobInstance->getType()->willReturn('type'); $jobInstance->getAlias()->willReturn('alias'); $filesystem->put('type/alias/id/invalid/invalid_items.csv', '')->shouldBeCalled(); $writer->setFilePath('/tmp/archivist/type/alias/id/invalid/invalid_items.csv')->shouldBeCalled(); $writer->initialize()->shouldBeCalled(); $writer->write(['items'])->shouldBeCalled(); $writer->flush()->shouldBeCalled(); $this->archive($jobExecution); }
/** * {@inheritdoc} */ public function archive(JobExecution $jobExecution) { foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) { if (!$step instanceof ItemStep) { continue; } $writer = $step->getWriter(); if ($writer instanceof FileWriter && $writer instanceof ArchivableWriterInterface && count($writer->getWrittenFiles()) > 1) { $filesystem = $this->getZipFilesystem($jobExecution, sprintf('%s.zip', pathinfo($writer->getPath(), PATHINFO_FILENAME))); foreach ($writer->getWrittenFiles() as $fullPath => $localPath) { $filesystem->write($localPath, file_get_contents($fullPath), true); } } } }
/** * Archive files used by job execution (input / output) * * @param JobExecution $jobExecution */ public function archive(JobExecution $jobExecution) { foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) { if (!$step instanceof ItemStep) { continue; } $writer = $step->getWriter(); if ($writer instanceof ArchivableWriterInterface && count($writer->getWrittenFiles()) > 1) { continue; } if ($writer instanceof FileWriter && is_file($path = $writer->getPath())) { $key = strtr($this->getRelativeArchivePath($jobExecution), array('%filename%' => basename($writer->getPath()))); $this->filesystem->write($key, file_get_contents($path), true); } } }
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)); }
public function testInitializeAndRead() { /** @var \PHPUnit_Framework_MockObject_MockObject|StepExecution $stepExecution */ $stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock(); $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface'); $this->contextRegistry->expects($this->once())->method('getByStepExecution')->with($stepExecution)->will($this->returnValue($context)); $this->executionContext = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext'); $this->jobExecution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution'); $this->jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($this->executionContext)); $data = $this->getData(); $this->executionContext->expects($this->once())->method('get')->will($this->returnValue($data)); $stepExecution->expects($this->once())->method('getJobExecution')->will($this->returnValue($this->jobExecution)); $reader = $this->getReader(); $reader->setStepExecution($stepExecution); foreach ($data as $item) { $this->assertEquals($item, $reader->read()); } $this->assertNull($reader->read()); }
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); }
function it_creates_a_file_if_writer_is_correct(CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step, $factory, $filesystem) { $jobExecution->getJobInstance()->willReturn($jobInstance); $jobExecution->getId()->willReturn(12); $jobInstance->getJob()->willReturn($job); $jobInstance->getType()->willReturn('type'); $jobInstance->getAlias()->willReturn('alias'); $job->getSteps()->willReturn([$step]); $step->getWriter()->willReturn($writer); $writer->getWrittenFiles()->willReturn(['/tmp/tmp' => 'tmp', '/tmp/tmp2' => 'tmp2']); $writer->getPath()->willReturn('/tmp/tmp'); $adapter = new LocalAdapter('/tmp'); $fs = new Filesystem($adapter); $fs->write('tmp', '', true); $fs->write('tmp2', '', true); $factory->createZip(Argument::any())->willReturn($filesystem); $filesystem->write('tmp', '', true)->shouldBeCalled(); $filesystem->write('tmp2', '', true)->shouldBeCalled(); $this->archive($jobExecution); }
function it_creates_a_file_if_writer_is_correct(CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step, $factory, $filesystem) { $file1 = tempnam(sys_get_temp_dir(), 'spec'); $file2 = tempnam(sys_get_temp_dir(), 'spec'); $jobExecution->getJobInstance()->willReturn($jobInstance); $jobExecution->getId()->willReturn(12); $jobInstance->getJob()->willReturn($job); $jobInstance->getType()->willReturn('type'); $jobInstance->getAlias()->willReturn('alias'); $job->getSteps()->willReturn([$step]); $step->getWriter()->willReturn($writer); $writer->getWrittenFiles()->willReturn([$file1 => 'file1', $file2 => 'file2']); $writer->getPath()->willReturn(sys_get_temp_dir()); $filesystem->has('type/alias/12/archive')->willReturn(false); $filesystem->createDir('type/alias/12/archive')->shouldBeCalled(); $factory->createZip(Argument::any())->willReturn($filesystem); $filesystem->put('file1', '')->shouldBeCalled(); $filesystem->put('file2', '')->shouldBeCalled(); $this->archive($jobExecution); unlink($file1); unlink($file2); }
/** * Mark a job execution as failed * @param JobExecution $jobExecution */ public function markAsFailed(JobExecution $jobExecution) { $jobExecution->setStatus(new BatchStatus(BatchStatus::FAILED)); $jobExecution->setExitStatus(new ExitStatus(ExitStatus::FAILED)); $jobExecution->setEndTime(new \DateTime('now')); $jobExecution->addFailureException(new \Exception('An exception occured during the job execution')); $this->entityManager->persist($jobExecution); $this->entityManager->flush(); }
function let(NotificationManager $manager, JobExecutionEvent $event, JobExecution $jobExecution, StepExecution $stepExecution, ArrayCollection $warnings, JobInstance $jobInstance, UserInterface $user, BatchStatus $status) { $this->beConstructedWith($manager); $jobExecution->getUser()->willReturn($user); $jobExecution->getStepExecutions()->willReturn([$stepExecution]); $jobExecution->getStatus()->willReturn($status); $jobExecution->getJobInstance()->willReturn($jobInstance); $stepExecution->getWarnings()->willReturn($warnings); $jobExecution->getId()->willReturn(5); $jobInstance->getType()->willReturn('export'); $jobInstance->getLabel()->willReturn('Foo export'); $event->getJobExecution()->willReturn($jobExecution); }
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); }
/** * Default mapping from throwable to {@link ExitStatus}. Clients can modify the exit code using a * {@link StepExecutionListener}. * * @param JobExecution $jobExecution Execution of the job * @param string $status Status of the execution * * @return an {@link ExitStatus} */ private function updateStatus(JobExecution $jobExecution, $status) { $jobExecution->setStatus(new BatchStatus($status)); }
/** * Returns true if the job has been executed without any warning * * @param JobExecution $jobExecution * * @return bool */ protected function executionComplete(JobExecution $jobExecution) { if (ExitStatus::COMPLETED !== $jobExecution->getExitStatus()->getExitCode()) { return false; } foreach ($jobExecution->getStepExecutions() as $stepExecution) { if (count($stepExecution->getWarnings())) { return false; } } return true; }
/** * Constructor with mandatory properties. * * @param string $stepName the step to which this execution belongs * @param JobExecution $jobExecution the current job execution */ public function __construct($stepName, JobExecution $jobExecution) { $this->stepName = $stepName; $this->jobExecution = $jobExecution; $jobExecution->addStepExecution($this); $this->warnings = new ArrayCollection(); $this->executionContext = new ExecutionContext(); $this->setStatus(new BatchStatus(BatchStatus::STARTING)); $this->setExitStatus(new ExitStatus(ExitStatus::EXECUTING)); $this->failureExceptions = array(); $this->errors = array(); $this->startTime = new \DateTime(); }
/** * @param JobExecution $jobExecution * @param string|UserInterface $user * @param string $type * @param string $status */ protected function generateMassEditNotify(JobExecution $jobExecution, $user, $type, $status) { $this->manager->notify([$user], sprintf('pim_mass_edit.notification.%s.%s', $type, $status), $status, ['route' => 'pim_enrich_job_tracker_show', 'routeParams' => ['id' => $jobExecution->getId()], 'messageParams' => ['%label%' => $jobExecution->getJobInstance()->getLabel()]]); }
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)); }
/** * @param JobExecution $jobExecution * @return array */ protected function collectErrors(JobExecution $jobExecution) { $errors = array(); foreach ($jobExecution->getStepExecutions() as $stepExecution) { $errors = array_merge($errors, $this->contextRegistry->getByStepExecution($stepExecution)->getErrors()); } return $errors; }
/** * @param JobExecution $jobExecution * @return bool */ protected function isClearSkipped(JobExecution $jobExecution) { if ($this->skipClear) { return true; } return (bool) $jobExecution->getExecutionContext()->get(self::JOB_SKIP_CLEAR); }