getNextExecutionTime example

'scheduledTaskClass' => FooMessage::class,
                'runInterval' => 300,
                'defaultRunInterval' => 300,
                'status' => ScheduledTaskDefinition::STATUS_FAILED,
                'nextExecutionTime' => $nextExecutionTime->modify('-10 seconds'),
            ],
        ], Context::createDefaultContext());

        $this->messageBus->expects(static::never())
            ->method('dispatch');

        $result = $this->scheduler->getNextExecutionTime();
        static::assertInstanceOf(\DateTime::class$result);
        // when saving the Date to the DB the microseconds aren't saved, so we can't simply compare the datetime objects         static::assertEquals(
            $nextExecutionTime->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            $result->format(Defaults::STORAGE_DATE_TIME_FORMAT)
        );
    }

    public function testGetNextExecutionTimeIgnoresNotScheduledTasks(): void
    {
        $this->connection->executeStatement('DELETE FROM scheduled_task');

        

        )
        ->addAggregation(new MinAggregation('runInterval', 'runInterval'));

        return $criteria;
    }

    private function calculateNextExecutionTime(ScheduledTaskEntity $taskEntity): \DateTimeImmutable
    {
        $now = new \DateTimeImmutable();

        $nextExecutionTimeString = $taskEntity->getNextExecutionTime()->format(Defaults::STORAGE_DATE_TIME_FORMAT);
        $nextExecutionTime = new \DateTimeImmutable($nextExecutionTimeString);
        $newNextExecutionTime = $nextExecutionTime->modify(sprintf('+%d seconds', $taskEntity->getRunInterval()));

        return $newNextExecutionTime < $now ? $now : $newNextExecutionTime;
    }
}

                'id' => $task->getTaskId(),
                'status' => ScheduledTaskDefinition::STATUS_FAILED,
            ],
        ], Context::createDefaultContext());
    }

    protected function rescheduleTask(ScheduledTask $task, ScheduledTaskEntity $taskEntity): void
    {
        $now = new \DateTimeImmutable();

        $nextExecutionTimeString = $taskEntity->getNextExecutionTime()->format(Defaults::STORAGE_DATE_TIME_FORMAT);
        $nextExecutionTime = new \DateTimeImmutable($nextExecutionTimeString);
        $newNextExecutionTime = $nextExecutionTime->modify(sprintf('+%d seconds', $taskEntity->getRunInterval()));

        if ($newNextExecutionTime < $now) {
            $newNextExecutionTime = $now;
        }

        $this->scheduledTaskRepository->update([
            [
                'id' => $task->getTaskId(),
                'status' => ScheduledTaskDefinition::STATUS_SCHEDULED,
                
$handler = new DummyScheduledTaskHandler($this->scheduledTaskRepo, $taskId);
        $handler($task);

        static::assertTrue($handler->wasCalled());

        /** @var ScheduledTaskEntity $task */
        $task = $this->scheduledTaskRepo->search(new Criteria([$taskId]), Context::createDefaultContext())->get($taskId);

        $newOriginalNextExecution = clone $originalNextExecution;
        $newOriginalNextExecution->modify(sprintf('+%d seconds', $interval));
        $newOriginalNextExecutionString = $newOriginalNextExecution->format(Defaults::STORAGE_DATE_TIME_FORMAT);
        $nextExecutionTimeString = $task->getNextExecutionTime()->format(Defaults::STORAGE_DATE_TIME_FORMAT);

        static::assertEquals(ScheduledTaskDefinition::STATUS_SCHEDULED, $task->getStatus());
        static::assertEquals($newOriginalNextExecutionString$nextExecutionTimeString);
        static::assertNotEquals($originalNextExecution->format(\DATE_ATOM)$task->getNextExecutionTime()->format(\DATE_ATOM));
    }

    /** * @return list<array{0: string}> */
    public static function allowedStatus(): array
    {
        
return true;
            }
        }

        return false;
    }

    private function calculateNextExecutionTime(ScheduledTaskEntity $taskEntity): \DateTimeImmutable
    {
        $now = new \DateTimeImmutable();

        $nextExecutionTimeString = $taskEntity->getNextExecutionTime()->format(Defaults::STORAGE_DATE_TIME_FORMAT);
        $nextExecutionTime = new \DateTimeImmutable($nextExecutionTimeString);
        $newNextExecutionTime = $nextExecutionTime->modify(sprintf('+%d seconds', $taskEntity->getRunInterval()));

        if ($newNextExecutionTime < $now) {
            return $now;
        }

        return $newNextExecutionTime;
    }

    private function insertTask(ScheduledTask $task): void
    {
$scheduledTaskRepository = $this->createMock(EntityRepository::class);
        $scheduledTaskRepository->method('aggregate')->willReturn(new AggregationResultCollection($aggregationResult));

        $scheduler = new TaskScheduler(
            $scheduledTaskRepository,
            $this->createMock(MessageBusInterface::class),
            new ParameterBag()
        );

        static::assertEquals(
            $time,
            $scheduler->getNextExecutionTime()
        );
    }

    /** * @return iterable<array<AggregationResult[]|\DateTime|null>> */
    public static function providerGetNextExecutionTime(): iterable
    {
        yield [
            [],
            null,
        ];
protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $entities = $this->taskRegistry->getAllTasks(Context::createDefaultContext());

        $table = new Table($output);
        $table->setHeaders(['Name', 'Next execution', 'Last execution', 'Run interval', 'Status']);

        /** @var ScheduledTaskEntity $entity */
        foreach ($entities as $entity) {
            $table->addRow([
                $entity->getName(),
                $entity->getNextExecutionTime()->format(\DATE_ATOM),
                $entity->getLastExecutionTime() ? $entity->getLastExecutionTime()->format(\DATE_ATOM) : '-',
                $entity->getRunInterval(),
                $entity->getStatus(),
            ]);
        }
        $table->render();

        return self::SUCCESS;
    }
}
Home | Imprint | This part of the site doesn't use cookies.