diff --git a/docs/bundle/config_reference.md b/docs/bundle/config_reference.md index d27877765..042b93cfa 100644 --- a/docs/bundle/config_reference.md +++ b/docs/bundle/config_reference.md @@ -67,6 +67,7 @@ enqueue: queue_name: ~ job: enabled: false + default_mapping: true async_events: enabled: false extensions: diff --git a/docs/bundle/job_queue.md b/docs/bundle/job_queue.md index eb1e25281..464ff0d0a 100644 --- a/docs/bundle/job_queue.md +++ b/docs/bundle/job_queue.md @@ -60,6 +60,9 @@ enqueue: # plus basic bundle configuration job: true + + # if you configure doctrine mapping yourself, disable default mapping + default_mapping: false doctrine: # plus basic bundle configuration diff --git a/pkg/enqueue-bundle/Consumption/Extension/DoctrineClearIdentityMapExtension.php b/pkg/enqueue-bundle/Consumption/Extension/DoctrineClearIdentityMapExtension.php index a8f258f21..e88076819 100644 --- a/pkg/enqueue-bundle/Consumption/Extension/DoctrineClearIdentityMapExtension.php +++ b/pkg/enqueue-bundle/Consumption/Extension/DoctrineClearIdentityMapExtension.php @@ -13,9 +13,6 @@ class DoctrineClearIdentityMapExtension implements MessageReceivedExtensionInter */ protected $registry; - /** - * @param ManagerRegistry $registry - */ public function __construct(ManagerRegistry $registry) { $this->registry = $registry; diff --git a/pkg/enqueue-bundle/DependencyInjection/Configuration.php b/pkg/enqueue-bundle/DependencyInjection/Configuration.php index 3b6367fda..070851e4e 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -94,6 +94,9 @@ private function getJobConfiguration(): ArrayNodeDefinition } return (new ArrayNodeDefinition('job')) + ->children() + ->booleanNode('default_mapping')->defaultTrue()->end() + ->end() ->addDefaultsIfNotSet() ->canBeEnabled() ; diff --git a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php index 10521b3a0..cc6c0500c 100644 --- a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php +++ b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php @@ -171,6 +171,14 @@ private function registerJobQueueDoctrineEntityMapping(ContainerBuilder $contain return; } + foreach ($container->getExtensionConfig('enqueue') as $modules) { + foreach ($modules as $config) { + if (isset($config['job']) && false === $config['job']['default_mapping']) { + return; + } + } + } + foreach ($container->getExtensionConfig('doctrine') as $config) { // do not register mappings if dbal not configured. if (!empty($config['dbal'])) { diff --git a/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php b/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php index e484f0bfd..49ae1c605 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php @@ -37,9 +37,6 @@ public function getLogDir() return sys_get_temp_dir().'/EnqueueBundle/cache/logs'; } - /** - * @param \Symfony\Component\Config\Loader\LoaderInterface $loader - */ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/config/config.yml'); diff --git a/pkg/job-queue/CalculateRootJobStatusService.php b/pkg/job-queue/CalculateRootJobStatusService.php index af4631e2a..4268158b1 100644 --- a/pkg/job-queue/CalculateRootJobStatusService.php +++ b/pkg/job-queue/CalculateRootJobStatusService.php @@ -12,17 +12,12 @@ class CalculateRootJobStatusService */ private $jobStorage; - /** - * @param JobStorage $jobStorage - */ public function __construct(JobStorage $jobStorage) { $this->jobStorage = $jobStorage; } /** - * @param Job $job - * * @return bool true if root job was stopped */ public function calculate(Job $job) @@ -91,11 +86,7 @@ protected function calculateRootJobStatus(array $jobs) $success++; break; default: - throw new \LogicException(sprintf( - 'Got unsupported job status: id: "%s" status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Got unsupported job status: id: "%s" status: "%s"', $job->getId(), $job->getStatus())); } } diff --git a/pkg/job-queue/DependentJobContext.php b/pkg/job-queue/DependentJobContext.php index 34deba656..04b898fd3 100644 --- a/pkg/job-queue/DependentJobContext.php +++ b/pkg/job-queue/DependentJobContext.php @@ -14,9 +14,6 @@ class DependentJobContext */ private $dependentJobs; - /** - * @param Job $job - */ public function __construct(Job $job) { $this->job = $job; diff --git a/pkg/job-queue/DependentJobProcessor.php b/pkg/job-queue/DependentJobProcessor.php index 6126be08f..4916c7031 100644 --- a/pkg/job-queue/DependentJobProcessor.php +++ b/pkg/job-queue/DependentJobProcessor.php @@ -30,11 +30,6 @@ class DependentJobProcessor implements Processor, TopicSubscriberInterface */ private $logger; - /** - * @param JobStorage $jobStorage - * @param ProducerInterface $producer - * @param LoggerInterface $logger - */ public function __construct(JobStorage $jobStorage, ProducerInterface $producer, LoggerInterface $logger) { $this->jobStorage = $jobStorage; diff --git a/pkg/job-queue/DependentJobService.php b/pkg/job-queue/DependentJobService.php index b6066d669..9ab500ba8 100644 --- a/pkg/job-queue/DependentJobService.php +++ b/pkg/job-queue/DependentJobService.php @@ -20,8 +20,6 @@ public function __construct(JobStorage $jobStorage) } /** - * @param Job $job - * * @return DependentJobContext */ public function createDependentJobContext(Job $job) @@ -29,16 +27,10 @@ public function createDependentJobContext(Job $job) return new DependentJobContext($job); } - /** - * @param DependentJobContext $context - */ public function saveDependentJob(DependentJobContext $context) { if (!$context->getJob()->isRoot()) { - throw new \LogicException(sprintf( - 'Only root jobs allowed but got child. jobId: "%s"', - $context->getJob()->getId() - )); + throw new \LogicException(sprintf('Only root jobs allowed but got child. jobId: "%s"', $context->getJob()->getId())); } $this->jobStorage->saveJob($context->getJob(), function (Job $job) use ($context) { diff --git a/pkg/job-queue/Doctrine/JobStorage.php b/pkg/job-queue/Doctrine/JobStorage.php index 32e20fe8d..89a79ac44 100644 --- a/pkg/job-queue/Doctrine/JobStorage.php +++ b/pkg/job-queue/Doctrine/JobStorage.php @@ -39,9 +39,13 @@ class JobStorage private $uniqueTableName; /** - * @param ManagerRegistry $doctrine - * @param string $entityClass - * @param string $uniqueTableName + * @var string + */ + private $entityManagerName; + + /** + * @param string $entityClass + * @param string $uniqueTableName */ public function __construct(ManagerRegistry $doctrine, $entityClass, $uniqueTableName) { @@ -90,7 +94,6 @@ public function findRootJobByOwnerIdAndJobName($ownerId, $jobName) /** * @param string $name - * @param Job $rootJob * * @return Job */ @@ -119,20 +122,13 @@ public function createJob() } /** - * @param Job $job - * @param \Closure|null $lockCallback - * * @throws DuplicateJobException */ public function saveJob(Job $job, \Closure $lockCallback = null) { $class = $this->getEntityRepository()->getClassName(); if (!$job instanceof $class) { - throw new \LogicException(sprintf( - 'Got unexpected job instance: expected: "%s", actual" "%s"', - $class, - get_class($job) - )); + throw new \LogicException(sprintf('Got unexpected job instance: expected: "%s", actual" "%s"', $class, get_class($job))); } if ($lockCallback) { @@ -175,11 +171,7 @@ public function saveJob(Job $job, \Closure $lockCallback = null) ]); } } catch (UniqueConstraintViolationException $e) { - throw new DuplicateJobException(sprintf( - 'Duplicate job. ownerId:"%s", name:"%s"', - $job->getOwnerId(), - $job->getName() - )); + throw new DuplicateJobException(sprintf('Duplicate job. ownerId:"%s", name:"%s"', $job->getOwnerId(), $job->getName())); } $this->getEntityManager()->persist($job); diff --git a/pkg/job-queue/Job.php b/pkg/job-queue/Job.php index 0468d7fdb..ef0c42c4e 100644 --- a/pkg/job-queue/Job.php +++ b/pkg/job-queue/Job.php @@ -237,8 +237,6 @@ public function getCreatedAt() * Do not call from the outside. * * @internal - * - * @param \DateTime $createdAt */ public function setCreatedAt(\DateTime $createdAt) { @@ -258,8 +256,6 @@ public function getStartedAt() * Do not call from the outside. * * @internal - * - * @param \DateTime $startedAt */ public function setStartedAt(\DateTime $startedAt) { @@ -279,8 +275,6 @@ public function getStoppedAt() * Do not call from the outside. * * @internal - * - * @param \DateTime $stoppedAt */ public function setStoppedAt(\DateTime $stoppedAt) { @@ -324,9 +318,6 @@ public function getData() return $this->data; } - /** - * @param array $data - */ public function setData(array $data) { $this->data = $data; diff --git a/pkg/job-queue/JobProcessor.php b/pkg/job-queue/JobProcessor.php index 8f197f742..06698f45c 100644 --- a/pkg/job-queue/JobProcessor.php +++ b/pkg/job-queue/JobProcessor.php @@ -17,10 +17,6 @@ class JobProcessor */ private $producer; - /** - * @param JobStorage $jobStorage - * @param ProducerInterface $producer - */ public function __construct(JobStorage $jobStorage, ProducerInterface $producer) { $this->jobStorage = $jobStorage; @@ -74,7 +70,6 @@ public function findOrCreateRootJob($ownerId, $jobName, $unique = false) /** * @param string $jobName - * @param Job $rootJob * * @return Job */ @@ -104,9 +99,6 @@ public function findOrCreateChildJob($jobName, Job $rootJob) return $job; } - /** - * @param Job $job - */ public function startChildJob(Job $job) { if ($job->isRoot()) { @@ -116,11 +108,7 @@ public function startChildJob(Job $job) $job = $this->jobStorage->findJobById($job->getId()); if (Job::STATUS_NEW !== $job->getStatus()) { - throw new \LogicException(sprintf( - 'Can start only new jobs: id: "%s", status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Can start only new jobs: id: "%s", status: "%s"', $job->getId(), $job->getStatus())); } $job->setStatus(Job::STATUS_RUNNING); @@ -131,9 +119,6 @@ public function startChildJob(Job $job) $this->sendCalculateRootJobStatusEvent($job); } - /** - * @param Job $job - */ public function successChildJob(Job $job) { if ($job->isRoot()) { @@ -143,11 +128,7 @@ public function successChildJob(Job $job) $job = $this->jobStorage->findJobById($job->getId()); if (Job::STATUS_RUNNING !== $job->getStatus()) { - throw new \LogicException(sprintf( - 'Can success only running jobs. id: "%s", status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Can success only running jobs. id: "%s", status: "%s"', $job->getId(), $job->getStatus())); } $job->setStatus(Job::STATUS_SUCCESS); @@ -158,9 +139,6 @@ public function successChildJob(Job $job) $this->sendCalculateRootJobStatusEvent($job); } - /** - * @param Job $job - */ public function failChildJob(Job $job) { if ($job->isRoot()) { @@ -170,11 +148,7 @@ public function failChildJob(Job $job) $job = $this->jobStorage->findJobById($job->getId()); if (Job::STATUS_RUNNING !== $job->getStatus()) { - throw new \LogicException(sprintf( - 'Can fail only running jobs. id: "%s", status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Can fail only running jobs. id: "%s", status: "%s"', $job->getId(), $job->getStatus())); } $job->setStatus(Job::STATUS_FAILED); @@ -185,9 +159,6 @@ public function failChildJob(Job $job) $this->sendCalculateRootJobStatusEvent($job); } - /** - * @param Job $job - */ public function cancelChildJob(Job $job) { if ($job->isRoot()) { @@ -197,11 +168,7 @@ public function cancelChildJob(Job $job) $job = $this->jobStorage->findJobById($job->getId()); if (!in_array($job->getStatus(), [Job::STATUS_NEW, Job::STATUS_RUNNING], true)) { - throw new \LogicException(sprintf( - 'Can cancel only new or running jobs. id: "%s", status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Can cancel only new or running jobs. id: "%s", status: "%s"', $job->getId(), $job->getStatus())); } $job->setStatus(Job::STATUS_CANCELLED); @@ -217,7 +184,6 @@ public function cancelChildJob(Job $job) } /** - * @param Job $job * @param bool $force */ public function interruptRootJob(Job $job, $force = false) @@ -245,8 +211,6 @@ public function interruptRootJob(Job $job, $force = false) /** * @see https://github.com/php-enqueue/enqueue-dev/pull/222#issuecomment-336102749 See for rationale - * - * @param Job $job */ protected function saveJob(Job $job) { @@ -255,8 +219,6 @@ protected function saveJob(Job $job) /** * @see https://github.com/php-enqueue/enqueue-dev/pull/222#issuecomment-336102749 See for rationale - * - * @param Job $job */ protected function sendCalculateRootJobStatusEvent(Job $job) { diff --git a/pkg/job-queue/JobRunner.php b/pkg/job-queue/JobRunner.php index afd445c67..e8d7eaa27 100644 --- a/pkg/job-queue/JobRunner.php +++ b/pkg/job-queue/JobRunner.php @@ -15,8 +15,7 @@ class JobRunner private $rootJob; /** - * @param JobProcessor $jobProcessor - * @param Job $rootJob + * @param Job $rootJob */ public function __construct(JobProcessor $jobProcessor, Job $rootJob = null) { @@ -25,9 +24,8 @@ public function __construct(JobProcessor $jobProcessor, Job $rootJob = null) } /** - * @param string $ownerId - * @param string $name - * @param callable $runCallback + * @param string $ownerId + * @param string $name * * @throws \Throwable|\Exception if $runCallback triggers an exception * @@ -54,11 +52,7 @@ public function runUnique($ownerId, $name, callable $runCallback) try { $this->jobProcessor->failChildJob($childJob); } catch (\Throwable $t) { - throw new OrphanJobException(sprintf( - 'Job cleanup failed. ID: "%s" Name: "%s"', - $childJob->getId(), - $childJob->getName() - ), 0, $e); + throw new OrphanJobException(sprintf('Job cleanup failed. ID: "%s" Name: "%s"', $childJob->getId(), $childJob->getName()), 0, $e); } throw $e; @@ -74,8 +68,7 @@ public function runUnique($ownerId, $name, callable $runCallback) } /** - * @param string $name - * @param callable $startCallback + * @param string $name * * @return mixed */ @@ -89,8 +82,7 @@ public function createDelayed($name, callable $startCallback) } /** - * @param string $jobId - * @param callable $runCallback + * @param string $jobId * * @return mixed */ diff --git a/pkg/job-queue/Test/DbalPersistedConnection.php b/pkg/job-queue/Test/DbalPersistedConnection.php index f1ec03035..51160c03b 100644 --- a/pkg/job-queue/Test/DbalPersistedConnection.php +++ b/pkg/job-queue/Test/DbalPersistedConnection.php @@ -102,9 +102,6 @@ protected function persistTransactionNestingLevel($level) static::$persistedTransactionNestingLevels[$this->getConnectionId()] = $level; } - /** - * @param DriverConnection $connection - */ protected function persistConnection(DriverConnection $connection) { static::$persistedConnections[$this->getConnectionId()] = $connection; diff --git a/pkg/job-queue/Tests/Functional/app/AppKernel.php b/pkg/job-queue/Tests/Functional/app/AppKernel.php index ce21df0b8..9e6a24812 100644 --- a/pkg/job-queue/Tests/Functional/app/AppKernel.php +++ b/pkg/job-queue/Tests/Functional/app/AppKernel.php @@ -36,9 +36,6 @@ public function getLogDir() return sys_get_temp_dir().'/EnqueueJobQueue/cache/logs'; } - /** - * @param \Symfony\Component\Config\Loader\LoaderInterface $loader - */ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/config/config.yml');