Skip to content

Async Symfony Messenger #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ with [FrankenPHP](https://frankenphp.dev) and [Caddy](https://caddyserver.com/)
7. [Using MySQL instead of PostgreSQL](docs/mysql.md)
8. [Using Alpine Linux instead of Debian](docs/alpine.md)
9. [Using a Makefile](docs/makefile.md)
10. [Updating the template](docs/updating.md)
11. [Troubleshooting](docs/troubleshooting.md)
10. [Using async Symfony Messenger](docs/symfony-messenger.md)
11. [Updating the template](docs/updating.md)
12. [Troubleshooting](docs/troubleshooting.md)

## License

Expand Down
72 changes: 72 additions & 0 deletions docs/symfony-messenger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Using async Symfony Messenger

Add new service to the `compose.yaml`:
```yaml
php-worker:
image: ${IMAGES_PREFIX:-}app-php-worker
restart: unless-stopped
environment:
- RUN_MIGRATIONS=false
healthcheck:
disable: true
depends_on:
- php
```

Add new services to the `compose.override.yaml`:
```yaml
php-worker:
profiles:
- donotstart

php-worker-async:
scale: 2
extends:
file: compose.yaml
service: php-worker
image: ${IMAGES_PREFIX:-}app-php-worker-async
build:
context: .
target: frankenphp_dev
command: ['/app/bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M']
volumes:
- ./:/app
- /app/var/
depends_on:
php:
condition: service_healthy
```

Two instances of `php-worker-async` will start after `php` container which does installation of Symfony. They will share app folder because of `- ./:/app` in volumes configuration. `- /app/var/` defines that every container will have its own and separate `/app/var/` folder, [note missing `:`](https://stackoverflow.com/questions/46166304/docker-compose-volumes-without-colon).

To add additional workers just copy `php-worker-async` service and replace every usage of the `async` in the new service with appropriate value for the new worker.

Add new service to the `compose.prod.yaml`:
```yaml
php-worker:
profiles:
- donotstart

php-worker-async:
scale: 2
extends:
file: compose.yaml
service: php-worker
image: ${IMAGES_PREFIX:-}app-php-worker-async
build:
context: .
target: frankenphp_dev
command: ['/app/bin/console', 'messenger:consume', 'async', '-vv', '--time-limit=60', '--limit=10', '--memory-limit=128M']
depends_on:
php:
condition: service_healthy
```

Apply the following changes to the `frankenphp/docker-entrypoint.sh`:
```patch
- if grep -q ^DATABASE_URL= .env; then
+ if grep -q ^DATABASE_URL= .env && [ "${RUN_MIGRATIONS:-true}" = "true" ]; then
```

> [!NOTE]
> After all changes are made the containers need to be rebuilt.