Skip to content

Commit

Permalink
Configuration du mailer + messages asynchrones (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarchois authored Jan 23, 2025
1 parent 97f7ab1 commit b55c87a
Show file tree
Hide file tree
Showing 18 changed files with 387 additions and 16 deletions.
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=[email protected]
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:*

##
## ----------------
## 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

0 comments on commit b55c87a

Please sign in to comment.