getMinRunInterval example

$endTime = $startTime + $timeLimit;
        }

        $memoryLimit = $input->getOption('memory-limit');
        if ($memoryLimit) {
            $memoryLimit = MemorySizeCalculator::convertToBytes($memoryLimit);
        }

        while (!$this->shouldStop) {
            $this->scheduler->queueScheduledTasks();

            $idleTime = $this->scheduler->getMinRunInterval() ?? 30;
            if ($endTime) {
                $remainingSeconds = $endTime - microtime(true);
                if ($remainingSeconds < $idleTime) {
                    $idleTime = $remainingSeconds;
                }
            }

            $idleTime = max(1, min((int) $idleTime, 15));

            sleep($idleTime);

            
#[Route(path: '/api/_action/scheduled-task/run', name: 'api.action.scheduled-task.run', methods: ['POST'])]     public function runScheduledTasks(): JsonResponse
    {
        $this->taskScheduler->queueScheduledTasks();

        return new JsonResponse(['message' => 'Success']);
    }

    #[Route(path: '/api/_action/scheduled-task/min-run-interval', name: 'api.action.scheduled-task.min-run-interval', methods: ['GET'])]     public function getMinRunInterval(): JsonResponse
    {
        return new JsonResponse(['minRunInterval' => $this->taskScheduler->getMinRunInterval()]);
    }
}
$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->getMinRunInterval()
        );
    }

    /** * @return iterable<array<AggregationResult[]|int|null>> */
    public static function providerGetMinRunInterval(): iterable
    {
        yield [
            [],
            null,
        ];
'scheduledTaskClass' => FooMessage::class,
                'runInterval' => 5,
                'defaultRunInterval' => 5,
                'status' => ScheduledTaskDefinition::STATUS_FAILED,
                'nextExecutionTime' => new \DateTime(),
            ],
        ], Context::createDefaultContext());

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

        static::assertEquals(5, $this->scheduler->getMinRunInterval());
    }

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

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

        static::assertNull($this->scheduler->getMinRunInterval());
    }
}
Home | Imprint | This part of the site doesn't use cookies.