Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed return types to EntityManagerInterface #260

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Command/CleanUpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use JMS\JobQueueBundle\Entity\Job;
use JMS\JobQueueBundle\Entity\Repository\JobManager;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -39,15 +39,15 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var EntityManager $em */
/** @var EntityManagerInterface $em */
$em = $this->registry->getManagerForClass(Job::class);
$con = $em->getConnection();

$this->cleanUpExpiredJobs($em, $con, $input);
$this->collectStaleJobs($em);
}

private function collectStaleJobs(EntityManager $em)
private function collectStaleJobs(EntityManagerInterface $em)
{
foreach ($this->findStaleJobs($em) as $job) {
if ($job->isRetried()) {
Expand All @@ -61,7 +61,7 @@ private function collectStaleJobs(EntityManager $em)
/**
* @return Job[]
*/
private function findStaleJobs(EntityManager $em)
private function findStaleJobs(EntityManagerInterface $em)
{
$excludedIds = array(-1);

Expand All @@ -86,7 +86,7 @@ private function findStaleJobs(EntityManager $em)
} while ($job !== null);
}

private function cleanUpExpiredJobs(EntityManager $em, Connection $con, InputInterface $input)
private function cleanUpExpiredJobs(EntityManagerInterface $em, Connection $con, InputInterface $input)
{
$incomingDepsSql = $con->getDatabasePlatform()->modifyLimitQuery("SELECT 1 FROM jms_job_dependencies WHERE dest_job_id = :id", 1);

Expand Down Expand Up @@ -116,7 +116,7 @@ private function cleanUpExpiredJobs(EntityManager $em, Connection $con, InputInt
$em->flush();
}

private function resolveDependencies(EntityManager $em, Job $job)
private function resolveDependencies(EntityManagerInterface $em, Job $job)
{
// If this job has failed, or has otherwise not succeeded, we need to set the
// incoming dependencies to failed if that has not been done already.
Expand All @@ -138,7 +138,7 @@ private function resolveDependencies(EntityManager $em, Job $job)
$em->getConnection()->executeUpdate("DELETE FROM jms_job_dependencies WHERE dest_job_id = :id", array('id' => $job->getId()));
}

private function findExpiredJobs(EntityManager $em, InputInterface $input)
private function findExpiredJobs(EntityManagerInterface $em, InputInterface $input)
{
$succeededJobs = function(array $excludedIds) use ($em, $input) {
return $em->createQuery("SELECT j FROM JMSJobQueueBundle:Job j WHERE j.closedAt < :maxRetentionTime AND j.originalJob IS NULL AND j.state = :succeeded AND j.id NOT IN (:excludedIds)")
Expand Down
4 changes: 2 additions & 2 deletions Command/MarkJobIncompleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace JMS\JobQueueBundle\Command;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use JMS\JobQueueBundle\Entity\Job;
use Symfony\Component\Console\Command\Command;
use JMS\JobQueueBundle\Entity\Repository\JobManager;
Expand Down Expand Up @@ -36,7 +36,7 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var EntityManager $em */
/** @var EntityManagerInterface $em */
$em = $this->registry->getManagerForClass(Job::class);

/** @var Job|null $job */
Expand Down
6 changes: 3 additions & 3 deletions Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace JMS\JobQueueBundle\Command;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use JMS\JobQueueBundle\Entity\Job;
use JMS\JobQueueBundle\Entity\Repository\JobManager;
use JMS\JobQueueBundle\Event\NewOutputEvent;
Expand Down Expand Up @@ -443,8 +443,8 @@ private function getBasicCommandLineArgs(): array
return $args;
}

private function getEntityManager(): EntityManager
private function getEntityManager(): EntityManagerInterface
{
return /** @var EntityManager */ $this->registry->getManagerForClass('JMSJobQueueBundle:Job');
return /** @var EntityManagerInterface */ $this->registry->getManagerForClass('JMSJobQueueBundle:Job');
}
}
6 changes: 3 additions & 3 deletions Command/ScheduleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace JMS\JobQueueBundle\Command;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
use JMS\JobQueueBundle\Console\CronCommand;
use JMS\JobQueueBundle\Cron\CommandScheduler;
Expand Down Expand Up @@ -113,7 +113,7 @@ private function scheduleJobs(OutputInterface $output, array $jobSchedulers, arr

private function acquireLock($commandName, \DateTime $lastRunAt)
{
/** @var EntityManager $em */
/** @var EntityManagerInterface $em */
$em = $this->registry->getManagerForClass(CronJob::class);
$con = $em->getConnection();

Expand Down Expand Up @@ -166,7 +166,7 @@ private function populateJobSchedulers()
return $schedulers;
}

private function populateJobsLastRunAt(EntityManager $em, array $jobSchedulers)
private function populateJobsLastRunAt(EntityManagerInterface $em, array $jobSchedulers)
{
$jobsLastRunAt = array();

Expand Down
4 changes: 2 additions & 2 deletions Controller/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace JMS\JobQueueBundle\Controller;

use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use JMS\JobQueueBundle\Entity\Job;
use JMS\JobQueueBundle\Entity\Repository\JobManager;
use JMS\JobQueueBundle\View\JobFilter;
Expand Down Expand Up @@ -149,7 +149,7 @@ public function retryJobAction(Job $job)
return new RedirectResponse($url, 201);
}

private function getEm(): EntityManager
private function getEm(): EntityManagerInterface
{
return $this->get('doctrine')->getManagerForClass(Job::class);
}
Expand Down
4 changes: 2 additions & 2 deletions Entity/Repository/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use JMS\JobQueueBundle\Entity\Job;
Expand Down Expand Up @@ -425,7 +425,7 @@ public function getAvailableJobsForQueueCount($jobQueue)
return count($result);
}

private function getJobManager(): EntityManager
private function getJobManager(): EntityManagerInterface
{
return $this->registry->getManagerForClass(Job::class);
}
Expand Down