From f2205ffec3313b4b1e459dc0cd01db67f58dbdce Mon Sep 17 00:00:00 2001 From: Arjan Oosting Date: Tue, 3 Nov 2015 15:32:48 +0100 Subject: [PATCH 1/2] Add states parameter to findJob --- Entity/Repository/JobRepository.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Entity/Repository/JobRepository.php b/Entity/Repository/JobRepository.php index f5bced31..83b46961 100644 --- a/Entity/Repository/JobRepository.php +++ b/Entity/Repository/JobRepository.php @@ -70,11 +70,24 @@ public function setRegistry(RegistryInterface $registry) $this->registry = $registry; } - public function findJob($command, array $args = array()) + public function findJob($command, array $args = array(), array $states = array()) { - return $this->_em->createQuery("SELECT j FROM JMSJobQueueBundle:Job j WHERE j.command = :command AND j.args = :args") + $qb = $this->_em->createQueryBuilder(); + + $qb->select('j') + ->from('JMSJobQueueBundle:Job', 'j') + ->where('j.command = :command') + ->andWhere('j.args = :args') ->setParameter('command', $command) ->setParameter('args', $args, Type::JSON_ARRAY) + ; + + if (!empty($states)) { + $qb ->andWhere('j.state IN (:states)') + ->setParameter('states', $states); + } + + return $qb->getQuery() ->setMaxResults(1) ->getOneOrNullResult(); } @@ -447,4 +460,4 @@ public function getAvailableJobsForQueueCount($jobQueue) return count($result); } -} \ No newline at end of file +} From dba68b1702928b62a75eb845415978074922c9bc Mon Sep 17 00:00:00 2001 From: Arjan Oosting Date: Tue, 3 Nov 2015 15:33:14 +0100 Subject: [PATCH 2/2] Add findOpenJob function --- Entity/Repository/JobRepository.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Entity/Repository/JobRepository.php b/Entity/Repository/JobRepository.php index 83b46961..1fb9258b 100644 --- a/Entity/Repository/JobRepository.php +++ b/Entity/Repository/JobRepository.php @@ -70,6 +70,11 @@ public function setRegistry(RegistryInterface $registry) $this->registry = $registry; } + public function findOpenJob($command, array $args = array()) + { + return $this->findJob($command, $args, array(Job::STATE_RUNNING, Job::STATE_PENDING, Job::STATE_NEW)); + } + public function findJob($command, array $args = array(), array $states = array()) { $qb = $this->_em->createQueryBuilder();