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
# .symfony.cloud.yaml workers: mails: commands: start: symfony 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.
symfony-deploy command before starting your worker is not
necessary anymore, SymfonyCloud takes care of running it automatically.
While worker and application containers share the same
size by default,
they usually benefit from being tweaked separately. Read the documentation
about resources allocations for more
details about using it.
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: