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

Configuration du mailer + messages asynchrones #1160

Merged
merged 2 commits into from
Jan 23, 2025
Merged
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
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ S3_ACCESS_KEY=""
S3_SECRET_KEY=""
S3_BUCKET=""
S3_ENDPOINT=""

MAILER_SENDER=no-reply@dialog.beta.gouv.fr
MAILER_DSN=smtp://mailer:1025
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ ci_metabase_export: ## Export data to Metabase
./tools/scalingodbtunnel dialog-metabase --host-url --port 10001 & ./tools/wait-for-it.sh 127.0.0.1:10001
make console CMD="app:metabase:export"

##
## ----------------
## Supervision
## ----------------
##

supervisor_status:
docker compose exec supervisor supervisorctl status

supervisor_restart:
docker compose exec supervisor supervisorctl restart messenger-worker:*

Comment on lines +298 to +308
Copy link
Collaborator

Choose a reason for hiding this comment

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

Je chipote peut-être mais, puisque Supervisor est utilisé pour démarrer le worker messenger en local, quid de le traiter comme un détail d'implémentation ?

Suggested change
## ----------------
## Supervision
## ----------------
##
supervisor_status:
docker compose exec supervisor supervisorctl status
supervisor_restart:
docker compose exec supervisor supervisorctl restart messenger-worker:*
## ----------------
## Workers (for local development)
## ----------------
##
workers_status:
docker compose exec supervisor supervisorctl status
workers_restart:
docker compose exec supervisor supervisorctl restart messenger-worker:*

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok je traiterai ton retour dans la prochaine PR

##
## ----------------
## Prod
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
web: bin/run
worker: php bin/console messenger:consume async --time-limit=300 --limit=50 --sleep=5 --failure-limit=5 --recover-timeout=30
postdeploy: make scalingo-postdeploy
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
"symfony/framework-bundle": "7.2.*",
"symfony/http-client": "7.2.*",
"symfony/lock": "7.2.*",
"symfony/mailer": "7.2.*",
"symfony/messenger": "7.2.*",
"symfony/mime": "7.2.*",
"symfony/monolog-bundle": "^3.8",
"symfony/rate-limiter": "7.2.*",
"symfony/redis-messenger": "7.2.*",
"symfony/runtime": "7.2.*",
"symfony/security-bundle": "7.2.*",
"symfony/translation": "7.2.*",
Expand Down
216 changes: 215 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/packages/mailer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
framework:
mailer:
dsn: '%env(MAILER_DSN)%'
envelope:
sender: '%env(MAILER_SENDER)%'
headers:
From: 'DiaLog <%env(MAILER_SENDER)%>'
25 changes: 11 additions & 14 deletions config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ framework:
- validation

transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
# async: '%env(MESSENGER_TRANSPORT_DSN)%'
# failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'

async:
dsn: "%env(REDIS_URL)%/messages"
retry_strategy:
max_retries: 3
delay: 1000
routing:
# Route your messages to the transports
# 'App\Message\YourMessage': async
'App\Application\AsyncCommandInterface': async

# when@test:
# framework:
# messenger:
# transports:
# # replace with your transport name here (e.g., my_transport: 'in-memory://')
# # For more Messenger testing tools, see https://github.com/zenstruck/messenger-test
# async: 'in-memory://'
when@test:
framework:
messenger:
transports:
async: 'sync://'
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ services:
- database
- redis

supervisor:
build:
context: ./docker/php
command: ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]
volumes:
- ./:/var/www/dialog
- ./docker/php/supervisor:/etc/supervisor
- ./var/log/supervisor:/var/log/supervisor
depends_on:
- database
- redis

nginx:
image: nginx:stable-alpine
ports:
Expand Down Expand Up @@ -68,3 +80,18 @@ services:
# Allow accessing host ports from this container via host.docker.internal on Linux
# https://stackoverflow.com/a/43541732
- host.docker.internal:host-gateway

mailer:
image: schickling/mailcatcher
ports:
- 1025:1025
- 1080:1080

redis-commander:
image: rediscommander/redis-commander
ports:
- "8081:8081"
environment:
- REDIS_HOSTS=local:redis:6379
depends_on:
- redis
6 changes: 6 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ RUN apt-get install -y wget && \
wget https://github.com/jgm/pandoc/releases/download/3.5/pandoc-3.5-1-amd64.deb && \
dpkg -i pandoc-3.5-1-amd64.deb

# Install Supervisor

RUN apt-get update && apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
COPY supervisor/supervisord.conf /etc/supervisor/supervisord.conf

# Allow husky to install pre-commit hooks
RUN git config --global --add safe.directory /var/www/dialog

Expand Down
7 changes: 7 additions & 0 deletions docker/php/supervisor/conf.d/messenger-worker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[program:messenger-worker]
command=php /var/www/dialog/bin/console messenger:consume async --time-limit=300 --memory-limit=256M --limit=50
numprocs=2
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d
user=www-data
Loading
Loading