Skip to content

Commit

Permalink
#29: Add background task for queue processing
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Jan 26, 2020
1 parent 1b1fdfe commit 540c568
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ ENV DEBIAN_FRONTEND=noninteractive \
# Asana importer app secret
TAIGA_IMPORTER_ASANA_APP_SECRET="" \
DEBUG=false \
# Default container user id
TAIGA_UID=1000 \
# Default container group id
TAIGA_GID=1000 \
# List of plugins to enable eg. "slack, other, other" or just "slack"
TAIGA_PLUGINS=""
TAIGA_PLUGINS="" \
# Interval (in seconds) for a background task that sends mails
MAIL_NOTIFICATIONS_SEND_EVERY=120

COPY bin/plugins/plugin-manager.py /opt/riotkit/bin/plugin-manager.py
COPY bin/plugins/plugin-manager.py /opt/riotkit/bin/
COPY bin/cron/send-mail-notifications.sh /opt/riotkit/bin/
COPY plugins /usr/src/taiga-plugins

# install dependencies
Expand Down Expand Up @@ -176,7 +181,7 @@ RUN cp /opt/taiga-conf/taiga/local.py /usr/src/taiga-back/settings/local.py \
&& mkdir -p /var/log/nginx /var/lib/nginx \
&& touch /var/run/nginx.pid

EXPOSE 80 443
EXPOSE 80 9001
VOLUME /usr/src/taiga-back/media
WORKDIR /usr/src/taiga-back

Expand Down
15 changes: 14 additions & 1 deletion README.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,20 @@ If you have trouble logging in or editing user settings it may be related to a f

2. Using existing database

See: https://github.com/riotkit-org/docker-taiga/issues/24
Set `TAIGA_DB_HOST` to point to your PostgreSQL hostname.
See also: https://github.com/riotkit-org/docker-taiga/issues/24

3. Debugging, getting logs

In container there is a supervisor configured. Use `supervisorctl` to access services.

Examples:
```bash
supervisorctl status send_app_notifications
supervisorctl tail -f send_app_notifications stderr
supervisorctl tail -f backend stderr
supervisorctl tail -f nginx stderr
```

Developing the container
------------------------
Expand Down
20 changes: 20 additions & 0 deletions bin/cron/send-mail-notifications.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

#
# Simple background task that sends queued e-mails
# - Does not interrupt on failure
# - Controlled by supervisord, logs are grabbed by supervisor
# - Shows logs on stdout and stderr
# - Does not introduce additional dependencies on cron, exim and 60mb+ of others
#

cd /usr/src/taiga-back

MAIL_NOTIFICATIONS_SEND_EVERY=${MAIL_NOTIFICATIONS_SEND_EVERY:-120}

while true; do
sleep ${MAIL_NOTIFICATIONS_SEND_EVERY}
echo " >> Sending all queued mails"
python manage.py send_notifications; exit_code=$?
echo " >> Done, exit code is ${exit_code}"
done
21 changes: 21 additions & 0 deletions supervisor.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[inet_http_server]
port=0.0.0.0:9001

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=http://127.0.0.1:9001

[supervisord]
logfile=/var/log/supervisord.log ; supervisord log file
logfile_maxbytes=5MB ; maximum size of logfile before rotation
Expand All @@ -6,6 +15,10 @@ loglevel=debug ; info, debug, warn, trace
nodaemon=true ; run supervisord as a daemon
user=root ; default user
childlogdir=/var/log ; where child log files will live
serverurl=unix:///run/supervisord.sock

[unix_http_server]
file=/run/supervisord.sock

[program:backend]
command=gunicorn --workers 4 --timeout 60 -b 127.0.0.1:8000 taiga.wsgi
Expand All @@ -16,3 +29,11 @@ stderr_events_enabled=true
command=nginx -c /etc/nginx/nginx.conf
stdout_events_enabled=true
stderr_events_enabled=true

[program:send_app_notifications]
user=taiga
autostart=true
autorestart=true
command=/bin/bash -c "/opt/riotkit/bin/send-mail-notifications.sh"
stdout_events_enabled=true
stderr_events_enabled=true

0 comments on commit 540c568

Please sign in to comment.