Skip to content

Commit a4ff0c7

Browse files
[Messenger] Add RunProcessMessage
1 parent e4799d5 commit a4ff0c7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

messenger.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,42 @@ on a case-by-case basis via the :class:`Symfony\\Component\\Messenger\\Stamp\\Se
18971897
provides that control. See `SymfonyCasts' message serializer tutorial`_ for
18981898
details.
18991899

1900+
Running External Processes
1901+
--------------------------
1902+
1903+
Messenger comes with a handy helper to easily run external processes by
1904+
dispatching a message. This takes advantages of the
1905+
:doc:`Process component </components/process>`. By dispatching a
1906+
:class:`Symfony\\Component\\Process\\Messenger\\RunProcessMessage`, Messenger
1907+
will take care of creating a new process with the parameters you passed
1908+
to the message::
1909+
1910+
use Symfony\Component\Messenger\MessageBusInterface;
1911+
use Symfony\Component\Process\Messenger\RunProcessMessage;
1912+
1913+
class CleanUpService
1914+
{
1915+
public function __construct(private MessageBusInterface $bus)
1916+
{
1917+
}
1918+
1919+
public function cleanUp(): void
1920+
{
1921+
$this->bus->dispatch(new RunProcessMessage(['rm', '-rf', 'var/log/temp/*'], cwd: '/my/custom/working-dir'));
1922+
1923+
// ...
1924+
}
1925+
}
1926+
1927+
Once handled, the message will contain many useful information such as the exit
1928+
code or the output of the process. You can refer to the page dedicated on
1929+
:doc:`handler results </messenger/handler_results>` for more information.
1930+
1931+
.. versionadded:: 6.4
1932+
1933+
The :class:`Symfony\\Component\\Process\\Messenger\\RunProcessMessage`
1934+
class was introduced in Symfony 6.4.
1935+
19001936
Customizing Handlers
19011937
--------------------
19021938

0 commit comments

Comments
 (0)