-
-
Notifications
You must be signed in to change notification settings - Fork 854
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
base: main
Are you sure you want to change the base?
Changes from all commits
817470a
e50c128
abf96f4
0d82aba
2639b9c
aa80aa2
a1bfdf2
0fb2915
71a4536
f058913
eeb912d
1678c4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scale was deprecated in compose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you share information where it was announced that this attribute became deprecated? This attribute is not deprecated in the specification (yet?) See: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. firstly chat gpt said this to me, then i checked if i'm wrong, then i am happy 😀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is about the This is about incompatibility of Docker Compose configuration migration from V2 to V3. This has been fixed (see docker/compose#5586 (comment)). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good then 👍 |
||
extends: | ||
file: compose.yaml | ||
service: php-worker | ||
image: ${IMAGES_PREFIX:-}app-php-worker-async | ||
build: | ||
context: . | ||
target: frankenphp_dev | ||
command: ['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, which are defined by `scale` property, of `php-worker-async` will start after `php` container which does installation of Symfony and runs database migrations. 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. | ||
|
||
In `compose.yaml` we have base `php-worker` service which is extended by `php-worker-async` in `compose.override.yaml` and in `compose.prod.yaml` with `extends` property. [`donotstart` service profile](https://docs.docker.com/compose/how-tos/profiles/) on `php-worker` service is used to prevent it from starting, because it is only used as a base for eventual multiple workers with different configuration. | ||
|
||
Add new services 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_prod | ||
command: ['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 | ||
k-37 marked this conversation as resolved.
Show resolved
Hide resolved
k-37 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
> [!NOTE] | ||
> After all changes are made the containers need to be rebuilt. |
Uh oh!
There was an error while loading. Please reload this page.