Workers (or consumers) are a great way to off-load processing in the background to make a website as snap as possible. Implementing workers in Symfony is made easy thanks to the Messenger component. This is why deploying workers is a first-class use-case with SymfonyCloud.
To deploy a worker, add an entry under the
1 2 3 4 5 6 7 8 9
# .symfony.cloud.yaml workers: mails: commands: start: | set -x -e (>&2 symfony-deploy) php bin/console messenger:consume --time-limit=60 --memory-limit=128M
On SymfonyCloud, worker containers run the exact same code as the web container. The container image is built only once, and then deployed multiple times in its own container along the web one. The build hook and dependencies may not vary but as these containers are independent they can be customized the same way using common properties (default values are the one defined for the main container):
commands.start key is required and specifies the command to use to
launch the application worker. It may be any valid shell command. If the command
specified by the
start key terminates it will be restarted automatically.
The deploy and post-deploy hooks are not run in worker containers.
Therefore you need to replicate the part of it required for your application
to be considered runnable. For usual Symfony application, it means running
(>&2 symfony-deploy) command before starting your worker.
Accessing a worker container¶
As for the web container, developers have access to container logs and console
using SSH. Using the Symfony CLI, one would use the
--worker flag to target
a specific worker. This flag uses the name of the worker, as defined by the key
used in the
This flag is available for the following commands:
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.