Job Launcher ============================================================ What is a job launcher? ------------------------------------------------------------ The job launcher is responsible for executing/scheduling every jobs. | Yeah, executing OR scheduling. There is multiple implementation of a job launcher across bridges. | Job’s execution might be asynchronous, and thus, when you ask the job launcher to “launch” a job, you have to check the ``JobExecution`` status that it had returned to know if the job is already executed. Architecture ------------------------------------------------------------ .. image:: /_static/images/diagram/overview.class.svg .. image:: /_static/images/diagram/overview.sequence.svg What is the simplest way to launch a job? ------------------------------------------------------------ .. code-block:: php new class implements JobInterface { public function execute(JobExecution $jobExecution): void { // your business logic } }, ]); $jobExecutionStorage = new NullJobExecutionStorage(); $launcher = new SimpleJobLauncher( new JobExecutionAccessor( new JobExecutionFactory(new UniqidJobExecutionIdGenerator(), new NullJobExecutionParametersBuilder()), $jobExecutionStorage, ), new JobExecutor(new JobRegistry($jobs), $jobExecutionStorage, null), ); $execution = $launcher->launch('your.job.name', ['job' => ['configuration']]); What types of launcher exists? ------------------------------------------------------------ **Built-in launchers:** * `SimpleJobLauncher `__: execute the job directly in the same PHP process. * `RoutingJobLauncher `__: pick the appropriate job launcher for each job, based on the configuration you provide. **Launchers from bridges:** * From ``symfony/console`` bridge: * `RunCommandJobLauncher `__: execute the job via an asynchronous symfony command. * From ``symfony/messenger`` bridge: * `DispatchMessageJobLauncher `__: execute the job via a symfony message dispatch. **Launchers for testing purpose:** * `BufferingJobLauncher `__: do not execute job, but store execution in a private var that can be accessed afterwards in your tests. .. seealso:: | :doc:`What is a job? ` | :doc:`What is a job execution? `