Skip to content

Commit

Permalink
added skipped to execution-repository
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed May 18, 2017
1 parent 37f1ff2 commit 5ef00c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Entity/TaskExecutionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,24 @@ public function findByTaskUuid($taskUuid)
/**
* {@inheritdoc}
*/
public function findNextScheduled(\DateTime $dateTime = null)
public function findNextScheduled(\DateTime $dateTime = null, array $skippedExecutions = [])
{
$query = $this->createQueryBuilder('e')
$queryBuilder = $this->createQueryBuilder('e')
->innerJoin('e.task', 't')
->where('e.status = :status')
->andWhere('e.scheduleTime < :date')
->setParameter('date', $dateTime ?: new \DateTime())
->setParameter('status', TaskStatus::PLANNED)
->setMaxResults(1)
->getQuery();
->setMaxResults(1);

$expr = $queryBuilder->expr();
if (!empty($skippedExecutions)) {
$queryBuilder->andWhere($expr->not($expr->in('e.uuid', ':skipped')))
->setParameter('skipped', $skippedExecutions);
}

try {
return $query->getSingleResult();
return $queryBuilder->getQuery()->getSingleResult();
} catch (NoResultException $exception) {
return null;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Functional/Entity/TaskExecutionRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ public function testFindScheduledFuture()
$this->assertNull($this->taskExecutionRepository->findNextScheduled());
}

public function testFindScheduledSkipped()
{
$task = $this->createTask();
$this->taskRepository->save($task);

$this->save($task, new \DateTime('+1 hour'));

$this->assertNull($this->taskExecutionRepository->findNextScheduled());
}

/**
* Save a new execution to database.
*
Expand Down

0 comments on commit 5ef00c2

Please sign in to comment.