8000 bug #49817 [Scheduler] Improve triggers performance when possible (fa… · symfony/symfony@9b0d811 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b0d811

Browse files
bug #49817 [Scheduler] Improve triggers performance when possible (fabpot)
This PR was merged into the 6.3 branch. Discussion ---------- [Scheduler] Improve triggers performance when possible | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes-ish | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT | Doc PR | n/a Using `\DatePeriod` for the default trigger is great as it takes care of all date/time idiosyncrasies. But for high frequencies, that does not work well and performance becomes an issue. So, this PR solves this issue by always using the fast algorithm when the frequency is expressed in seconds (int) or an ISO period (like `PT2S`) or when created from a string that uses a "simple" expression (like `2 seconds`). /cc `@upyx` Commits ------- ebcced6 [Scheduler] Improve triggers performance when possible
2 parents 3f9fe23 + ebcced6 commit 9b0d811

File tree

8 files changed

+398
-359
lines changed

8 files changed

+398
-359
lines changed

src/Symfony/Component/Scheduler/RecurringMessage.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Symfony\Component\Scheduler\Exception\InvalidArgumentException;
1515
use Symfony\Component\Scheduler\Trigger\CronExpressionTrigger;
16-
use Symfony\Component\Scheduler\Trigger\DateIntervalTrigger;
1716
use Symfony\Component\Scheduler\Trigger\JitterTrigger;
17+
use Symfony\Component\Scheduler\Trigger\PeriodicalTrigger;
1818
use Symfony\Component\Scheduler\Trigger\TriggerInterface;
1919

2020
/**
@@ -31,17 +31,21 @@ private function __construct(
3131
}
3232

3333
/**
34-
* Uses a relative date format to define the frequency.
34+
* Sets the trigger frequency.
3535
*
36+
* Supported frequency formats:
37+
*
38+
* * An integer to define the frequency as a number of seconds;
39+
* * An ISO 8601 duration format;
40+
* * A relative date format as supported by \DateInterval;
41+
* * A \DateInterval instance.
42+
*
43+
* @see https://en.wikipedia.org/wiki/ISO_8601#Durations
3644
* @see https://php.net/datetime.formats.relative
3745
*/
38-
public static function every(string $frequency, object $message, string|\DateTimeImmutable $from = new \DateTimeImmutable(), string|\DateTimeImmutable $until = new \DateTimeImmutable('3000-01-01')): self
46+
public static function every(string|int|\DateInterval $frequency, object $message, string|\DateTimeImmutable $from = new \DateTimeImmutable(), string|\DateTimeImmutable $until = new \DateTimeImmutable('3000-01-01')): self
3947
{
40-
if (false === $interval = \DateInterval::createFromDateString($frequency)) {
41-
throw new InvalidArgumentException(sprintf('Frequency "%s" cannot be parsed.', $frequency));
42-
}
43-
44-
return new self(new DateIntervalTrigger($interval, $from, $until), $message);
48+
return new self(new PeriodicalTrigger($frequency, $from, $until), $message);
4549
}
4650

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

src/Symfony/Component/Scheduler/Tests/Trigger/AbstractTriggerTestCase.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/Symfony/Component/Scheduler/Tests/Trigger/DateIntervalTriggerTest.php

Lines changed: 0 additions & 136 deletions
This file was deleted.

src/Symfony/Component/Scheduler/Tests/Trigger/DatePeriodTriggerTest.php

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0