Skip to content

Commit

Permalink
Add supervisor for consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnymilton committed May 6, 2024
1 parent c141b83 commit 392cbd8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ DATABASE_URL="postgresql://postgres:postgres@postgres:5432/flex_server?serverVer
###< doctrine/doctrine-bundle ###

REDIS_URL="redis://redis:6379"
MESSENGER_CONSUMER_NAME=null
1 change: 1 addition & 0 deletions backend/config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ framework:
dsn: '%app.messenger.redis_dsn%'
options:
serializer: !php/const Redis::SERIALIZER_NONE
consumer: '%env(MESSENGER_CONSUMER_NAME)%'
# failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'

Expand Down
5 changes: 3 additions & 2 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ FROM php:8.2-fpm
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

RUN apt update -y && \
apt install -y zip libzip-dev libpq-dev libicu-dev nginx &&\
apt install -y zip libzip-dev libpq-dev libicu-dev nginx supervisor &&\
docker-php-ext-install zip pdo pdo_pgsql intl opcache && \
pecl install redis && \
docker-php-ext-enable redis


COPY /docker/app/php/www.conf /usr/local/etc/php-fpm.d/www.conf

RUN rm /usr/local/etc/php-fpm.d/zz-docker.conf && \
Expand All @@ -27,6 +26,8 @@ COPY /docker/app/php/opcache.ini $PHP_INI_DIR/conf.d

COPY /docker/app/nginx/flex-server.conf /etc/nginx/conf.d/

COPY /docker/app/supervisor/messenger-worker.conf /etc/supervisor/conf.d/messenger-worker.conf

WORKDIR /application

ENV APP_ENV=prod
Expand Down
4 changes: 2 additions & 2 deletions docker/app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
composer dump-env prod
bin/console cache:clear
bin/console cache:clear && chown www-data:www-data var/cache -R
bin/console doctrine:database:create --if-not-exists -n
bin/console doctrine:migrations:migrate -n --allow-no-migration
supervisord -c /etc/supervisor/supervisord.conf && supervisorctl reread && supervisorctl update && supervisorctl start messenger-consume:*
php-fpm
nginx
bin/console messenger:consume async --time-limit=3600
bash
10 changes: 10 additions & 0 deletions docker/app/supervisor/messenger-worker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[program:messenger-consume]
command=php /application/bin/console messenger:consume async --time-limit=3600
user=www-data
numprocs=1
startsecs=0
autostart=true
autorestart=true
startretries=10
process_name=%(program_name)s_%(process_num)02d
environment=MESSENGER_CONSUMER_NAME=%(program_name)s_%(process_num)02d

0 comments on commit 392cbd8

Please sign in to comment.