Skip to content

Commit ded7d5b

Browse files
committed
feature #49813 [Messenger][Process] add RunProcessMessage and RunProcessMessageHandler (kbond)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Messenger][Process] add `RunProcessMessage` and `RunProcessMessageHandler` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | todo When reviewing how I could replace my cron scheduler with symfony/scheduler, I realized I need a way to schedule processes. ## Usage ```php use Symfony\Component\Process\Exception\RunProcessFailedException; use Symfony\Component\Process\Messenger\RunProcessMessage; try { $context = $bus->dispatch(new RunProcessMessage('something')); $context->exitCode; // int $context->output; // string $context->errorOutput; // string catch(RunProcessFailedException $e) { $e->context->exitCode; // int $e->context->output; // string $e->context->errorOutput; // string } ``` TODO: - [x] wire up - [x] tests Commits ------- abde61a807 [Messenger][Process] add `RunProcessMessage` and `RunProcessMessageHandler`
2 parents 8b498eb + 91852ff commit ded7d5b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
use Symfony\Component\Notifier\Recipient\Recipient;
130130
use Symfony\Component\Notifier\TexterInterface;
131131
use Symfony\Component\Notifier\Transport\TransportFactoryInterface as NotifierTransportFactoryInterface;
132+
use Symfony\Component\Process\Messenger\RunProcessMessageHandler;
132133
use Symfony\Component\PropertyAccess\PropertyAccessor;
133134
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
134135
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
@@ -240,6 +241,12 @@ public function load(array $configs, ContainerBuilder $container)
240241

241242
$container->registerAliasForArgument('parameter_bag', PsrContainerInterface::class);
242243

244+
$loader->load('process.php');
245+
246+
if (!class_exists(RunProcessMessageHandler::class)) {
247+
$container->removeDefinition('process.messenger.process_message_handler');
248+
}
249+
243250
if ($this->hasConsole()) {
244251
$loader->load('console.php');
245252

Resources/config/process.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Process\Messenger\RunProcessMessageHandler;
15+
16+
return static function (ContainerConfigurator $container) {
17+
$container
18+
->services()
19+
->set('process.messenger.process_message_handler', RunProcessMessageHandler::class)
20+
->tag('messenger.message_handler')
21+
;
22+
};

0 commit comments

Comments
 (0)