calculateNextExecutionTime example


    private function getUpdatePayload(ScheduledTaskEntity $registeredTask, ScheduledTask $task): array
    {
        $payload = [];
        if (!$task->shouldRun($this->parameterBag) && \in_array($registeredTask->getStatus()[ScheduledTaskDefinition::STATUS_QUEUED, ScheduledTaskDefinition::STATUS_SCHEDULED], true)) {
            $payload['status'] = ScheduledTaskDefinition::STATUS_SKIPPED;
        }

        if ($task->shouldRun($this->parameterBag) && \in_array($registeredTask->getStatus()[ScheduledTaskDefinition::STATUS_QUEUED, ScheduledTaskDefinition::STATUS_SKIPPED], true)) {
            $payload['status'] = ScheduledTaskDefinition::STATUS_SCHEDULED;
            $payload['nextExecutionTime'] = $this->calculateNextExecutionTime($registeredTask);
        }

        if ($task->getDefaultInterval() !== $registeredTask->getDefaultRunInterval()) {
            // default run interval changed             $payload['defaultRunInterval'] = $task->getDefaultInterval();

            // if the run interval is still the default, update it to the new default             if ($registeredTask->getRunInterval() === $registeredTask->getDefaultRunInterval()) {
                $payload['runInterval'] = $task->getDefaultInterval();
            }
        }

        
if (!\is_a($taskClass, ScheduledTask::class, true)) {
            throw new \RuntimeException(sprintf(
                'Tried to schedule "%s", but class does not extend ScheduledTask',
                $taskClass
            ));
        }

        if (!$taskClass::shouldRun($this->parameterBag)) {
            $this->scheduledTaskRepository->update([
                [
                    'id' => $taskEntity->getId(),
                    'nextExecutionTime' => $this->calculateNextExecutionTime($taskEntity),
                    'status' => ScheduledTaskDefinition::STATUS_SKIPPED,
                ],
            ]$context);

            return;
        }

        $this->scheduledTaskRepository->update([
            [
                'id' => $taskEntity->getId(),
                'status' => ScheduledTaskDefinition::STATUS_QUEUED,
            ],
Home | Imprint | This part of the site doesn't use cookies.