8000 [Scheduler] Add --date to schedule:debug · symfony/symfony@df83bf4 · GitHub
[go: up one dir, main page]

Skip to content

Commit df83bf4

Browse files
committed
[Scheduler] Add --date to schedule:debug
1 parent 0ba946a commit df83bf4

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)
0