Skip to content

Commit 4a1d96d

Browse files
committed
minor #20278 [Scheduler] Add example about how to pass arguments to a Symfony command (W0rma)
This PR was merged into the 6.4 branch. Discussion ---------- [Scheduler] Add example about how to pass arguments to a Symfony command We recently wanted to pass arguments to a Symfony command which is configured for the scheduler component with the `#[AsPeriodicTask]` attribute. The syntax mentioned in symfony/symfony#51525 (comment) worked. This PR adds an example to the docs. Commits ------- fc90d83 [Scheduler] Add example about how to pass arguments to a Symfony command
2 parents 53b7a44 + fc90d83 commit 4a1d96d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scheduler.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,20 @@ The attribute takes more parameters to customize the trigger::
473473
// defines the timezone to use
474474
#[AsCronTask('0 0 * * *', timezone: 'Africa/Malabo')]
475475

476+
Arguments/options for Symfony commands are passed as plain string::
477+
478+
use Symfony\Component\Console\Command\Command;
479+
480+
#[AsCronTask('0 0 * * *', arguments: 'arg --my-option')]
481+
class MyCommand extends Command
482+
{
483+
protected function configure(): void
484+
{
485+
$this->addArgument('my-arg');
486+
$this->addOption('my-option');
487+
}
488+
}
489+
476490
.. versionadded:: 6.4
477491

478492
The :class:`Symfony\\Component\\Scheduler\\Attribute\\AsCronTask` attribute
@@ -522,6 +536,20 @@ The ``#[AsPeriodicTask]`` attribute takes many parameters to customize the trigg
522536
}
523537
}
524538

539+
Arguments/options for Symfony commands are passed as plain string::
540+
541+
use Symfony\Component\Console\Command\Command;
542+
543+
#[AsPeriodicTask(frequency: '1 day', arguments: 'arg --my-option')]
544+
class MyCommand extends Command
545+
{
546+
protected function configure(): void
547+
{
548+
$this->addArgument('my-arg');
549+
$this->addOption('my-option');
550+
}
551+
}
552+
525553
.. versionadded:: 6.4
526554

527555
The :class:`Symfony\\Component\\Scheduler\\Attribute\\AsPeriodicTask` attribute

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