Skip to content

Commit f956606

Browse files
committed
feature #51244 [Scheduler] Add --date to schedule:debug (fabpot)
This PR was merged into the 6.4 branch. Discussion ---------- [Scheduler] Add --date to schedule:debug | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | 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 When using `schedule:debug`, it's nice to be able to see the next run date not only based on the current date, but maybe from a future date to validate that everything is well configured. Commits ------- df83bf4 [Scheduler] Add --date to schedule:debug
2 parents fa3d5d4 + df83bf4 commit f956606

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Symfony/Component/Scheduler/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
6.4
55
---
66

7+
* Add `--date` to `schedule:debug`
78
* Allow setting timezone of next run date in CronExpressionTrigger
89
* Add `AbstractTriggerDecorator`
910
* Make `ScheduledStamp` "send-able"

src/Symfony/Component/Scheduler/Command/DebugCommand.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ protected function configure(): void
4747
{
4848
$this
4949
->addArgument('schedule', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, sprintf('The schedule name (one of "%s")', implode('", "', $this->scheduleNames)), null, $this->scheduleNames)
50+
->addOption('date', null, InputArgument::OPTIONAL, 'The date to use for the next run date', 'now')
5051
->setHelp(<<<'EOF'
5152
The <info>%command.name%</info> lists schedules and their recurring messages:
5253
@@ -56,6 +57,10 @@ protected function configure(): void
5657
5758
<info>php %command.full_name% default</info>
5859
60+
You can also specify a date to use for the next run date:
61+
62+
<info>php %command.full_name% --date=2025-10-18</info>
63+
5964
EOF
6065
)
6166
;
@@ -72,6 +77,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7277
return 2;
7378
}
7479

80+
$date = new \DateTimeImmutable($input->getOption('date'));
81+
if ('now' !== $input->getOption('date')) {
82+
$io->comment(sprintf('All next run dates computed from %s.', $date->format(\DateTimeInterface::ATOM)));
83+
}
84+
7585
foreach ($names as $name) {
7686
$io->section($name);
7787

@@ -84,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8494
}
8595
$io->table(
8696
['Message', 'Trigger', 'Next Run'],
87-
array_map(self::renderRecurringMessage(...), $messages),
97+
array_map(self::renderRecurringMessage(...), $messages, array_fill(0, count($messages), $date)),
8898
);
8999
}
90100

@@ -94,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
94104
/**
95105
* @return array{0:string,1:string,2:string}
96106
*/
97-
private static function renderRecurringMessage(RecurringMessage $recurringMessage): array
107+
private static function renderRecurringMessage(RecurringMessage $recurringMessage, \DateTimeImmutable $date): array
98108
{
99109
$message = $recurringMessage->getMessage();
100110
$trigger = $recurringMessage->getTrigger();
@@ -117,7 +127,7 @@ private static function renderRecurringMessage(RecurringMessage $recurringMessag
117127
return [
118128
$messageName,
119129
$triggerName,
120-
$recurringMessage->getTrigger()->getNextRunDate(now())?->format(\DateTimeInterface::ATOM) ?? '-',
130+
$recurringMessage->getTrigger()->getNextRunDate($date)?->format(\DateTimeInterface::ATOM) ?? '-',
121131
];
122132
}
123133
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy