Skip to content

[Scheduler] Add --all to debug:schedule #51263

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 4, 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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Scheduler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGELOG
---

* Mark the component as non experimental
* Add `--date` to `schedule:debug`
* Add `--date` and `--all` options to the `schedule:debug` command
* Allow setting timezone of next run date in CronExpressionTrigger
* Add `AbstractTriggerDecorator`
* Make `ScheduledStamp` "send-able"
Expand Down
28 changes: 17 additions & 11 deletions src/Symfony/Component/Scheduler/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Scheduler\RecurringMessage;
use Symfony\Component\Scheduler\ScheduleProviderInterface;
use Symfony\Contracts\Service\ServiceProviderInterface;

use function Symfony\Component\Clock\now;

/**
* Command to list/debug schedules.
*
Expand All @@ -45,7 +44,8 @@ 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')
->addOption('date', null, InputOption::VALUE_REQUIRED, 'The date to use for the next run date', 'now')
->addOption('all', null, InputOption::VALUE_NONE, 'Display all recurring messages, including the terminated ones')
->setHelp(<<<'EOF'
The <info>%command.name%</info> lists schedules and their recurring messages:

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

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

To also display the terminated recurring messages, use the <info>--all</info> option:

<info>php %command.full_name% --all</info>

EOF
)
;
Expand Down Expand Up @@ -92,17 +96,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$io->table(
['Message', 'Trigger', 'Next Run'],
array_map(self::renderRecurringMessage(...), $messages, array_fill(0, count($messages), $date)),
array_filter(array_map(self::renderRecurringMessage(...), $messages, array_fill(0, count($messages), $date), array_fill(0, count($messages), $input->getOption('all')))),
);
}

return 0;
}

/**
* @return array{0:string,1:string,2:string}
* @return array{0:string,1:string,2:string}|null
*/
private static function renderRecurringMessage(RecurringMessage $recurringMessage, \DateTimeImmutable $date): array
private static function renderRecurringMessage(RecurringMessage $recurringMessage, \DateTimeImmutable $date, bool $all): ?array
{
$message = $recurringMessage->getMessage();
$trigger = $recurringMessage->getTrigger();
Expand All @@ -111,10 +115,12 @@ private static function renderRecurringMessage(RecurringMessage $recurringMessag
$message = $message->getMessage();
}

return [
$message instanceof \Stringable ? (string) $message : (new \ReflectionClass($message))->getShortName(),
(string) $trigger,
$trigger->getNextRunDate($date)?->format('r') ?? '-',
];
$next = $trigger->getNextRunDate($date)?->format('r') ?? '-';
if ('-' === $next && !$all) {
return null;
}
$name = $message instanceof \Stringable ? (string) $message : (new \ReflectionClass($message))->getShortName();

return [$name, (string) $trigger, $next];
}
}
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