-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
k-37
wants to merge
12
commits into
dunglas:main
Choose a base branch
from
k-37:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
817470a
Update README.md
k-37 e50c128
Create symfony-messenger.md
k-37 abf96f4
Apply suggestions from code review
k-37 0d82aba
Update symfony-messenger.md
k-37 2639b9c
Update symfony-messenger.md
k-37 aa80aa2
Update symfony-messenger.md
k-37 a1bfdf2
Update symfony-messenger.md
k-37 0fb2915
Update symfony-messenger.md
k-37 71a4536
Update symfony-messenger.md
k-37 f058913
Update symfony-messenger.md
k-37 eeb912d
Update symfony-messenger.md
k-37 1678c4c
Update symfony-messenger.md
k-37 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.