Skip to content
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

Async Symfony Messenger #681

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
62 changes: 62 additions & 0 deletions docs/symfony-messenger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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
```
Comment on lines +4 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```yaml
php-worker:
image: ${IMAGES_PREFIX:-}app-php-worker
restart: unless-stopped
environment:
- RUN_MIGRATIONS=false
healthcheck:
disable: true
depends_on:
- php
```
```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:
build:
context: .
target: frankenphp_prod
environment:
APP_SECRET: ${APP_SECRET}
```
Comment on lines +45 to +52

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```yaml
php-worker:
build:
context: .
target: frankenphp_prod
environment:
APP_SECRET: ${APP_SECRET}
```
```yaml
php-worker:
build:
context: .
target: frankenphp_prod
environment:
APP_SECRET: ${APP_SECRET}


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe combine these lines into one?

Suggested change
+ run_migrations=${RUN_MIGRATIONS:-true}
+ if grep -q ^DATABASE_URL= .env && [ "$run_migrations" = "true" ]; then
+ if grep -q ^DATABASE_URL= .env && [ "${RUN_MIGRATIONS:-true}" = "true" ]; then

```

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