Skip to content

[Scheduler] Add --date to schedule:debug #51244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Scheduler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
6.4
---

* Add `--date` to `schedule:debug`
* Allow setting timezone of next run date in CronExpressionTrigger
* Add `AbstractTriggerDecorator`
* Make `ScheduledStamp` "send-able"
Expand Down
16 changes: 13 additions & 3 deletions src/Symfony/Component/Scheduler/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected function configure(): void
{
$this
->addArgument('schedule', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, sprintf('The schedule name (one of "%s")', implode('", "', $this->scheduleNames)), null, $this->scheduleNames)
->addOption('date', null, InputArgument::OPTIONAL, 'The date to use for the next run date', 'now')
->setHelp(<<<'EOF'
The <info>%command.name%</info> lists schedules and their recurring messages:

Expand All @@ -56,6 +57,10 @@ protected function configure(): void

<info>php %command.full_name% default</info>

You can also specify a date to use for the next run date:

<info>php %command.full_name% --date=2025-10-18</info>

EOF
)
;
Expand All @@ -72,6 +77,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 2;
}

$date = new \DateTimeImmutable($input->getOption('date'));
if ('now' !== $input->getOption('date')) {
$io->comment(sprintf('All next run dates computed from %s.', $date->format(\DateTimeInterface::ATOM)));
}

foreach ($names as $name) {
$io->section($name);

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

Expand All @@ -94,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/**
* @return array{0:string,1:string,2:string}
*/
private static function renderRecurringMessage(RecurringMessage $recurringMessage): array
private static function renderRecurringMessage(RecurringMessage $recurringMessage, \DateTimeImmutable $date): array
{
$message = $recurringMessage->getMessage();
$trigger = $recurringMessage->getTrigger();
Expand All @@ -117,7 +127,7 @@ private static function renderRecurringMessage(RecurringMessage $recurringMessag
return [
$messageName,
$triggerName,
$recurringMessage->getTrigger()->getNextRunDate(now())?->format(\DateTimeInterface::ATOM) ?? '-',
$recurringMessage->getTrigger()->getNextRunDate($date)?->format(\DateTimeInterface::ATOM) ?? '-',
];
}
}