Skip to content

Commit

Permalink
[Scheduler] Improve triggers performance when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 22, 2023
1 parent 746c06b commit ebcced6
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 359 deletions.
20 changes: 12 additions & 8 deletions src/Symfony/Component/Scheduler/RecurringMessage.php
Expand Up @@ -13,8 +13,8 @@

use Symfony\Component\Scheduler\Exception\InvalidArgumentException;
use Symfony\Component\Scheduler\Trigger\CronExpressionTrigger;
use Symfony\Component\Scheduler\Trigger\DateIntervalTrigger;
use Symfony\Component\Scheduler\Trigger\JitterTrigger;
use Symfony\Component\Scheduler\Trigger\PeriodicalTrigger;
use Symfony\Component\Scheduler\Trigger\TriggerInterface;

/**
Expand All @@ -31,17 +31,21 @@ private function __construct(
}

/**
* Uses a relative date format to define the frequency.
* Sets the trigger frequency.
*
* Supported frequency formats:
*
* * An integer to define the frequency as a number of seconds;
* * An ISO 8601 duration format;
* * A relative date format as supported by \DateInterval;
* * A \DateInterval instance.
*
* @see https://en.wikipedia.org/wiki/ISO_8601#Durations
* @see https://php.net/datetime.formats.relative
*/
public static function every(string $frequency, object $message, string|\DateTimeImmutable $from = new \DateTimeImmutable(), string|\DateTimeImmutable $until = new \DateTimeImmutable('3000-01-01')): self
public static function every(string|int|\DateInterval $frequency, object $message, string|\DateTimeImmutable $from = new \DateTimeImmutable(), string|\DateTimeImmutable $until = new \DateTimeImmutable('3000-01-01')): self
{
if (false === $interval = \DateInterval::createFromDateString($frequency)) {
throw new InvalidArgumentException(sprintf('Frequency "%s" cannot be parsed.', $frequency));
}

return new self(new DateIntervalTrigger($interval, $from, $until), $message);
return new self(new PeriodicalTrigger($frequency, $from, $until), $message);
}

public static function cron(string $expression, object $message): self
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit ebcced6

Please sign in to comment.