File tree 1 file changed +36
-0
lines changed
Filter options
1 file changed +36
-0
lines changed
Original file line number Diff line number Diff line change @@ -1897,6 +1897,42 @@ on a case-by-case basis via the :class:`Symfony\\Component\\Messenger\\Stamp\\Se
1897
1897
provides that control. See `SymfonyCasts' message serializer tutorial `_ for
1898
1898
details.
1899
1899
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
+
1900
1936
Customizing Handlers
1901
1937
--------------------
1902
1938
You can’t perform that action at this time.
0 commit comments