Skip to content

Commit bee1b9d

Browse files
committed
feature #51263 [Scheduler] Add --all to debug:schedule (fabpot)
This PR was merged into the 6.4 branch. Discussion ---------- [Scheduler] Add --all to debug:schedule | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no <!-- 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 If you have many terminated recurring messages, it pollutes the output. As this command displays the future next date run, I propose to remove terminated messages from the output. The `--all` option allows you to display them all. Commits ------- a120c04 [Scheduler] Add --all to debug:schedule
2 parents ec7d86a + a120c04 commit bee1b9d

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/Symfony/Component/Scheduler/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CHANGELOG
55
---
66

77
* Mark the component as non experimental
8-
* Add `--date` to `schedule:debug`
8+
* Add `--date` and `--all` options to the `schedule:debug` command
99
* Allow setting timezone of next run date in CronExpressionTrigger
1010
* Add `AbstractTriggerDecorator`
1111
* Make `ScheduledStamp` "send-able"

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
use Symfony\Component\Console\Command\Command;
1616
use Symfony\Component\Console\Input\InputArgument;
1717
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920
use Symfony\Component\Console\Style\SymfonyStyle;
2021
use Symfony\Component\Messenger\Envelope;
2122
use Symfony\Component\Scheduler\RecurringMessage;
2223
use Symfony\Component\Scheduler\ScheduleProviderInterface;
2324
use Symfony\Contracts\Service\ServiceProviderInterface;
2425

25-
use function Symfony\Component\Clock\now;
26-
2726
/**
2827
* Command to list/debug schedules.
2928
*
@@ -45,7 +44,8 @@ protected function configure(): void
4544
{
4645
$this
4746
->addArgument('schedule', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, sprintf('The schedule name (one of "%s")', implode('", "', $this->scheduleNames)), null, $this->scheduleNames)
48-
->addOption('date', null, InputArgument::OPTIONAL, 'The date to use for the next run date', 'now')
47+
->addOption('date', null, InputOption::VALUE_REQUIRED, 'The date to use for the next run date', 'now')
48+
->addOption('all', null, InputOption::VALUE_NONE, 'Display all recurring messages, including the terminated ones')
4949
->setHelp(<<<'EOF'
5050
The <info>%command.name%</info> lists schedules and their recurring messages:
5151
@@ -59,6 +59,10 @@ protected function configure(): void
5959
6060
<info>php %command.full_name% --date=2025-10-18</info>
6161
62+
To also display the terminated recurring messages, use the <info>--all</info> option:
63+
64+
<info>php %command.full_name% --all</info>
65+
6266
EOF
6367
)
6468
;
@@ -92,17 +96,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9296
}
9397
$io->table(
9498
['Message', 'Trigger', 'Next Run'],
95-
array_map(self::renderRecurringMessage(...), $messages, array_fill(0, count($messages), $date)),
99+
array_filter(array_map(self::renderRecurringMessage(...), $messages, array_fill(0, count($messages), $date), array_fill(0, count($messages), $input->getOption('all')))),
96100
);
97101
}
98102

99103
return 0;
100104
}
101105

102106
/**
103-
* @return array{0:string,1:string,2:string}
107+
* @return array{0:string,1:string,2:string}|null
104108
*/
105-
private static function renderRecurringMessage(RecurringMessage $recurringMessage, \DateTimeImmutable $date): array
109+
private static function renderRecurringMessage(RecurringMessage $recurringMessage, \DateTimeImmutable $date, bool $all): ?array
106110
{
107111
$message = $recurringMessage->getMessage();
108112
$trigger = $recurringMessage->getTrigger();
@@ -111,10 +115,12 @@ private static function renderRecurringMessage(RecurringMessage $recurringMessag
111115
$message = $message->getMessage();
112116
}
113117

114-
return [
115-
$message instanceof \Stringable ? (string) $message : (new \ReflectionClass($message))->getShortName(),
116-
(string) $trigger,
117-
$trigger->getNextRunDate($date)?->format('r') ?? '-',
118-
];
118+
$next = $trigger->getNextRunDate($date)?->format('r') ?? '-';
119+
if ('-' === $next && !$all) {
120+
return null;
121+
}
122+
$name = $message instanceof \Stringable ? (string) $message : (new \ReflectionClass($message))->getShortName();
123+
124+
return [$name, (string) $trigger, $next];
119125
}
120126
}

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