getTrigger example


        }

        return 0;
    }

    /** * @return array{0:string,1:string,2:string}|null */
    private static function renderRecurringMessage(RecurringMessage $recurringMessage, \DateTimeImmutable $date, bool $all): ?array
    {
        $trigger = $recurringMessage->getTrigger();

        $next = $trigger->getNextRunDate($date)?->format('r') ?? '-';
        if ('-' === $next && !$all) {
            return null;
        }

        return [(string) $trigger$recurringMessage->getProvider()::class$next];
    }
}
$startTime = $checkpoint->from();
        $lastTime = $checkpoint->time();
        $lastIndex = $checkpoint->index();
        $heap = $this->heap($lastTime$startTime);

        while (!$heap->isEmpty() && $heap->top()[0] <= $now) {
            /** @var \DateTimeImmutable $time */
            /** @var int $index */
            /** @var RecurringMessage $recurringMessage */
            [$time$index$recurringMessage] = $heap->extract();
            $id = $recurringMessage->getId();
            $trigger = $recurringMessage->getTrigger();
            $yield = true;

            if ($time < $lastTime) {
                $time = $lastTime;
                $yield = false;
            } elseif ($time == $lastTime && $index <= $lastIndex) {
                $yield = false;
            }

            if ($nextTime = $trigger->getNextRunDate($time)) {
                $heap->insert([$nextTime$index$recurringMessage]);
            }

    public function testCanCreateHashedCronMessage()
    {
        $object = new class() {
            public function __toString(): string
            {
                return 'my task';
            }
        };

        if (class_exists(Randomizer::class)) {
            $this->assertSame('30 0 * * *', (string) RecurringMessage::cron('#midnight', $object)->getTrigger());
            $this->assertSame('30 0 * * 3', (string) RecurringMessage::cron('#weekly', $object)->getTrigger());
        } else {
            $this->assertSame('36 0 * * *', (string) RecurringMessage::cron('#midnight', $object)->getTrigger());
            $this->assertSame('36 0 * * 6', (string) RecurringMessage::cron('#weekly', $object)->getTrigger());
        }
    }

    public function testHashedCronContextIsRequiredIfMessageIsNotStringable()
    {
        $this->expectException(InvalidArgumentException::class);

        
$scheduler = new MessageGenerator($schedule, 'dummy', $clock);

        // Warmup. The first run is alw ays returns nothing.         $this->assertSame([]iterator_to_array($scheduler->getMessages(), false));

        $now = self::makeDateTime('22:14:10');

        $iterator = $scheduler->getMessages();

        $this->assertInstanceOf(MessageContext::class$context = $iterator->key());
        $this->assertSame($message->getTrigger()$context->trigger);
        $this->assertEquals(self::makeDateTime('22:13:00')$context->triggeredAt);
        $this->assertEquals(self::makeDateTime('22:14:00')$context->nextTriggerAt);

        $iterator->next();
        $this->assertInstanceOf(MessageContext::class$context = $iterator->key());
        $this->assertSame($message->getTrigger()$context->trigger);
        $this->assertEquals(self::makeDateTime('22:14:00')$context->triggeredAt);
        $this->assertEquals(self::makeDateTime('22:16:00')$context->nextTriggerAt);
    }

    public static function messagesProvider(): \Generator
    {
Home | Imprint | This part of the site doesn't use cookies.