Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/Command/DebugTasksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$page = $input->getOption('page');
$pageSize = $input->getOption('page-size');

$executions = $this->taskExecutionRepository->findAll($page, $pageSize);
$executions = $this->taskExecutionRepository->findAllPaginated($page, $pageSize);

$table = new Table($output);
$table->setHeaders(['uuid', 'status', 'handler', 'schedule time', 'end time', 'duration']);
Expand All @@ -76,8 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$execution->getUuid(),
$execution->getStatus(),
$execution->getHandlerClass(),
$execution->getScheduleTime()->format(\DateTime::RFC3339),
!$execution->getEndTime() ? '' : $execution->getEndTime()->format(\DateTime::RFC3339),
$execution->getScheduleTime()->format(\DateTimeImmutable::RFC3339),
!$execution->getEndTime() ? '' : $execution->getEndTime()->format(\DateTimeImmutable::RFC3339),
(round($execution->getDuration(), 6) * 1000000) . 'ms',
]
);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ScheduleSystemTasksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private function disableSystemTask($systemKey)
*/
public function disableTask(TaskInterface $task)
{
$task->setInterval($task->getInterval(), $task->getFirstExecution(), new \DateTime());
$task->setInterval($task->getInterval(), $task->getFirstExecution(), new \DateTimeImmutable());

return $this->abortPending($task);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Command/ScheduleTaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (null !== $cronExpression) {
$endDate = null;
if (null !== $endDateString) {
$endDate = new \DateTime($endDateString);
$endDate = new \DateTimeImmutable($endDateString);
}

$taskBuilder->cron($cronExpression, new \DateTime(), $endDate);
$taskBuilder->cron($cronExpression, new \DateTimeImmutable(), $endDate);
}

if (null !== $executionDateString) {
$taskBuilder->executeAt(new \DateTime($executionDateString));
$taskBuilder->executeAt(new \DateTimeImmutable($executionDateString));
}

$taskBuilder->schedule();
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getInterval()
/**
* {@inheritdoc}
*/
public function setInterval(CronExpression $interval, \DateTime $firstExecution = null, \DateTime $lastExecution = null)
public function setInterval(CronExpression $interval, \DateTimeImmutable $firstExecution = null, \DateTimeImmutable $lastExecution = null)
{
parent::setInterval($interval, $firstExecution, $lastExecution);

Expand Down
16 changes: 8 additions & 8 deletions src/Entity/TaskExecutionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TaskExecutionRepository extends EntityRepository implements TaskExecutionR
/**
* {@inheritdoc}
*/
public function create(TaskInterface $task, \DateTime $scheduleTime)
public function create(TaskInterface $task, \DateTimeImmutable $scheduleTime)
{
return new TaskExecution($task, $task->getHandlerClass(), $scheduleTime, $task->getWorkload());
}
Expand All @@ -36,8 +36,8 @@ public function create(TaskInterface $task, \DateTime $scheduleTime)
*/
public function save(TaskExecutionInterface $execution)
{
$this->_em->persist($execution);
$this->_em->flush($execution);
$this->getEntityManager()->persist($execution);
$this->getEntityManager()->flush($execution);

return $this;
}
Expand All @@ -47,16 +47,16 @@ public function save(TaskExecutionInterface $execution)
*/
public function remove(TaskExecutionInterface $execution)
{
$this->_em->remove($execution);
$this->_em->flush($execution);
$this->getEntityManager()->remove($execution);
$this->getEntityManager()->flush($execution);

return $this;
}

/**
* {@inheritdoc}
*/
public function findAll($page = 1, $pageSize = null)
public function findAllPaginated(int $page = 1, ?int $pageSize = null): array
{
$query = $this->createQueryBuilder('e')
->innerJoin('e.task', 't')
Expand Down Expand Up @@ -129,13 +129,13 @@ public function findByTaskUuid($taskUuid)
/**
* {@inheritdoc}
*/
public function findNextScheduled(\DateTime $dateTime = null, array $skippedExecutions = [])
public function findNextScheduled(\DateTimeImmutable $dateTime = null, array $skippedExecutions = [])
{
$queryBuilder = $this->createQueryBuilder('e')
->innerJoin('e.task', 't')
->where('e.status = :status')
->andWhere('e.scheduleTime < :date')
->setParameter('date', $dateTime ?: new \DateTime())
->setParameter('date', $dateTime ?: new \DateTimeImmutable())
->setParameter('status', TaskStatus::PLANNED)
->setMaxResults(1);

Expand Down
17 changes: 8 additions & 9 deletions src/Entity/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Task\TaskBundle\Entity;

use DateTime;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Task\TaskInterface;
Expand Down Expand Up @@ -44,8 +43,8 @@ public function findByUuid($uuid)
*/
public function save(TaskInterface $task)
{
$this->_em->persist($task);
$this->_em->flush($task);
$this->getEntityManager()->persist($task);
$this->getEntityManager()->flush($task);

return $this;
}
Expand All @@ -55,16 +54,16 @@ public function save(TaskInterface $task)
*/
public function remove(TaskInterface $task)
{
$this->_em->remove($task);
$this->_em->flush($task);
$this->getEntityManager()->remove($task);
$this->getEntityManager()->flush($task);

return $this;
}

/**
* {@inheritdoc}
*/
public function findAll($page = 1, $pageSize = null): array
public function findAllPaginated(int $page = 1, ?int $pageSize = null): array
{
$query = $this->createQueryBuilder('t')
->getQuery();
Expand All @@ -82,17 +81,17 @@ public function findAll($page = 1, $pageSize = null): array
*/
public function findEndBeforeNow()
{
return $this->findEndBefore(new \DateTime());
return $this->findEndBefore(new \DateTimeImmutable());
}

/**
* Returns task where last-execution is before given date-time.
*
* @param \DateTime $dateTime
* @param \DateTimeImmutable $dateTime
*
* @return TaskInterface[]
*/
public function findEndBefore(\DateTime $dateTime)
public function findEndBefore(\DateTimeImmutable $dateTime)
{
return $this->createQueryBuilder('t')
->where('t.lastExecution IS NULL OR t.lastExecution > :dateTime')
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/doctrine/Task.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

<field name="handlerClass" type="string" length="255"/>
<field name="intervalExpression" type="string" length="255" nullable="true"/>
<field name="firstExecution" type="datetime" nullable="true"/>
<field name="lastExecution" type="datetime" nullable="true"/>
<field name="firstExecution" type="datetime_immutable" nullable="true"/>
<field name="lastExecution" type="datetime_immutable" nullable="true"/>
<field name="systemKey" type="string" nullable="true" unique="true" length="191"/>
<field name="workload" type="object"/>
<field name="workload" type="json"/>

</entity>
</doctrine-mapping>
11 changes: 5 additions & 6 deletions src/Resources/config/doctrine/TaskExecution.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
</id>

<field name="handlerClass" type="string" length="255"/>
<field name="workload" type="object"/>
<field name="workload" type="json"/>
<field name="duration" type="float" nullable="true"/>
<field name="startTime" type="datetime" nullable="true"/>
<field name="endTime" type="datetime" nullable="true"/>
<field name="scheduleTime" column="schedule_time" type="datetime"/>
<field name="startTime" type="datetime_immutable" nullable="true"/>
<field name="endTime" type="datetime_immutable" nullable="true"/>
<field name="scheduleTime" column="schedule_time" type="datetime_immutable"/>
<field name="exception" type="text" nullable="true"/>
<field name="result" type="object" nullable="true"/>
<field name="result" type="json" nullable="true"/>
<field name="status" type="string" length="20"/>
<field name="attempts" type="integer"/>

<many-to-one target-entity="Task\TaskBundle\Entity\Task" field="task">
<join-column name="task_id" referenced-column-name="uuid" on-delete="CASCADE"/>
</many-to-one>

</entity>
</doctrine-mapping>
6 changes: 3 additions & 3 deletions tests/Functional/BaseCommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function createTask($workload, CronExpression $cronExpression = null,
{
$task = $this->taskRepository->create($handlerClass, $workload);
if ($cronExpression) {
$task->setInterval($cronExpression, new \DateTime(), new \DateTime('+1 year'));
$task->setInterval($cronExpression, new \DateTimeImmutable(), new \DateTimeImmutable('+1 year'));
}
$this->taskRepository->save($task);

Expand All @@ -113,12 +113,12 @@ protected function createTask($workload, CronExpression $cronExpression = null,
* Create task-execution.
*
* @param TaskInterface $task
* @param \DateTime $scheduleTime
* @param \DateTimeImmutable $scheduleTime
* @param string $status
*
* @return TaskExecutionInterface
*/
protected function createTaskExecution(TaskInterface $task, \DateTime $scheduleTime, $status = TaskStatus::PLANNED)
protected function createTaskExecution(TaskInterface $task, \DateTimeImmutable $scheduleTime, $status = TaskStatus::PLANNED)
{
$execution = $this->taskExecutionRepository->create($task, $scheduleTime);
$execution->setStatus($status);
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/BaseDatabaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ protected function createTask($handlerClass = TestHandler::class)
* Create a new task-execution.
*
* @param TaskInterface $task
* @param \DateTime $scheduleTime
* @param \DateTimeImmutable $scheduleTime
* @param string $status
*
* @return TaskExecution
*/
protected function createTaskExecution(TaskInterface $task, \DateTime $scheduleTime, $status = TaskStatus::PLANNED)
protected function createTaskExecution(TaskInterface $task, \DateTimeImmutable $scheduleTime, $status = TaskStatus::PLANNED)
{
$execution = new TaskExecution($task, $task->getHandlerClass(), $scheduleTime);
$execution->setStatus($status);
Expand Down
10 changes: 5 additions & 5 deletions tests/Functional/Command/DebugTasksCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function testExecute()

/** @var TaskExecutionInterface[] $executions */
$executions = [
$this->createTaskExecution($task, new \DateTime('-1 hour'), TaskStatus::COMPLETED),
$this->createTaskExecution($task, new \DateTime('-2 hour'), TaskStatus::COMPLETED),
$this->createTaskExecution($task, new \DateTimeImmutable('-1 hour'), TaskStatus::COMPLETED),
$this->createTaskExecution($task, new \DateTimeImmutable('-2 hour'), TaskStatus::COMPLETED),
];

$executions[0]->setResult(strrev($executions[0]->getWorkload()));
Expand Down Expand Up @@ -59,9 +59,9 @@ public function testExecutePaginated()

/** @var TaskExecutionInterface[] $executions */
$executions = [
$this->createTaskExecution($task, new \DateTime('-1 hour')),
$this->createTaskExecution($task, new \DateTime('-2 hour')),
$this->createTaskExecution($task, new \DateTime('+1 hour')),
$this->createTaskExecution($task, new \DateTimeImmutable('-1 hour')),
$this->createTaskExecution($task, new \DateTimeImmutable('-2 hour')),
$this->createTaskExecution($task, new \DateTimeImmutable('+1 hour')),
];

if (self::$kernel->getContainer()->has('doctrine')) {
Expand Down
16 changes: 8 additions & 8 deletions tests/Functional/Command/RunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function testExecute()

/** @var TaskExecutionInterface[] $executions */
$executions = [
$this->createTaskExecution($singleTask, new \DateTime('-1 hour')),
$this->createTaskExecution($laterTask, new \DateTime('+1 hour')),
$this->createTaskExecution($intervalTask, new \DateTime('-2 hour')),
$this->createTaskExecution($singleTask, new \DateTimeImmutable('-1 hour')),
$this->createTaskExecution($laterTask, new \DateTimeImmutable('+1 hour')),
$this->createTaskExecution($intervalTask, new \DateTimeImmutable('-2 hour')),
];

$this->commandTester->execute(
Expand Down Expand Up @@ -61,7 +61,7 @@ public function testExecute()
$this->assertGreaterThan(0, $execution->getDuration());
$this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime());

$result = $this->taskExecutionRepository->findAll(2, 3);
$result = $this->taskExecutionRepository->findAllPaginated(2, 3);
$this->assertCount(1, $result);

$task = $result[0]->getTask();
Expand Down Expand Up @@ -89,9 +89,9 @@ public function testExecuteWithFail()

/** @var TaskExecutionInterface[] $executions */
$executions = [
$this->createTaskExecution($singleTask, new \DateTime('-1 hour')),
$this->createTaskExecution($laterTask, new \DateTime('+1 hour')),
$this->createTaskExecution($intervalTask, new \DateTime('-2 hour')),
$this->createTaskExecution($singleTask, new \DateTimeImmutable('-1 hour')),
$this->createTaskExecution($laterTask, new \DateTimeImmutable('+1 hour')),
$this->createTaskExecution($intervalTask, new \DateTimeImmutable('-2 hour')),
];

$this->commandTester->execute(
Expand Down Expand Up @@ -119,7 +119,7 @@ public function testExecuteWithFail()
$this->assertGreaterThan(0, $execution->getDuration());
$this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime());

$result = $this->taskExecutionRepository->findAll(2, 3);
$result = $this->taskExecutionRepository->findAllPaginated(2, 3);
$this->assertCount(1, $result);

$task = $result[0]->getTask();
Expand Down
6 changes: 3 additions & 3 deletions tests/Functional/Command/ScheduleTaskCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ public function testExecuteWithWorkloadAndInterval()

public function testExecuteWithWorkloadAndIntervalAndEndDate()
{
$date = new \DateTime('+1 day');
$date = new \DateTimeImmutable('+1 day');
$this->commandTester->execute(
[
'command' => $this->command->getName(),
'handlerClass' => TestHandler::class,
'workload' => 'Test workload 1',
'--cron-expression' => '0 * * * *',
'--end-date' => $date->format(\DateTime::RFC3339),
'--end-date' => $date->format(\DateTimeImmutable::RFC3339),
]
);

Expand All @@ -99,7 +99,7 @@ public function testExecuteWithWorkloadAndIntervalAndEndDate()

public function testExecuteWithExecutionDate()
{
$date = new \DateTime('+1 day');
$date = new \DateTimeImmutable('+1 day');
$this->commandTester->execute(
[
'command' => $this->command->getName(),
Expand Down
Loading