User supervisord in docker to start supercronic and gunicorn
This commit is contained in:
parent
88e7e0edcc
commit
d8bce90b8e
|
|
@ -31,7 +31,7 @@ RUN curl -fsSLO "$SUPERCRONIC_URL" \
|
|||
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
|
||||
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
|
||||
|
||||
COPY ./compose/django/send_attendance_course_reminders /app/send_attendance_course_reminders
|
||||
COPY ./compose/django/supercronic_crontab /app/supercronic_crontab
|
||||
|
||||
# Python build stage
|
||||
FROM python as python-build-stage
|
||||
|
|
@ -42,6 +42,7 @@ ARG BUILD_ENVIRONMENT=production
|
|||
RUN apt-get install --no-install-recommends -y \
|
||||
# dependencies for building Python packages
|
||||
build-essential \
|
||||
# supervisor \
|
||||
# psycopg2 dependencies
|
||||
libpq-dev \
|
||||
git
|
||||
|
|
@ -119,6 +120,11 @@ RUN chown django:django ${APP_HOME}
|
|||
|
||||
USER django
|
||||
|
||||
RUN pip install supervisor
|
||||
RUN exit
|
||||
|
||||
EXPOSE 7555
|
||||
|
||||
COPY ./compose/django/supervisord.conf /app/supervisord.conf
|
||||
|
||||
ENTRYPOINT ["/entrypoint"]
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@ else
|
|||
python /app/manage.py migrate
|
||||
fi
|
||||
|
||||
if [[ $IT_APP_ENVIRONMENT != dev* ]]; then
|
||||
# Start periodic tasks
|
||||
/usr/local/bin/supercronic -sentry-dsn "$IT_SENTRY_DSN" -split-logs /app/send_attendance_course_reminders &
|
||||
# Use sentry for supercronic only in prod* environments
|
||||
if [[ $IT_APP_ENVIRONMENT == prod* ]]; then
|
||||
sed -i 's|command=/usr/local/bin/supercronic /app/supercronic_crontab|command=/usr/local/bin/supercronic /app/supercronic_crontab -sentry-dsn "$IT_SENTRY_DSN"|' /app/supervisord.conf
|
||||
fi
|
||||
|
||||
newrelic-admin run-program gunicorn config.asgi --bind 0.0.0.0:7555 --chdir=/app -k uvicorn.workers.UvicornWorker
|
||||
# Set the command to run supervisord
|
||||
/home/django/.local/bin/supervisord -c /app/supervisord.conf
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
@daily /usr/local/bin/python /app/manage.py send_attendance_course_reminders
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# Run every minute
|
||||
*/1 * * * * echo "hello"
|
||||
|
||||
# Run every 6 hours
|
||||
0 */6 * * * /usr/local/bin/python /app/manage.py simple_dummy_job
|
||||
|
||||
# every day at 19:30
|
||||
30 19 * * * /usr/local/bin/python /app/manage.py send_attendance_course_reminders
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
[supervisord]
|
||||
nodaemon=true
|
||||
|
||||
[program:supercronic]
|
||||
command=/usr/local/bin/supercronic /app/supercronic_crontab
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
|
||||
[program:gunicorn]
|
||||
command=newrelic-admin run-program gunicorn config.asgi --bind 0.0.0.0:7555 --chdir=/app -k uvicorn.workers.UvicornWorker
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import structlog
|
||||
|
||||
from vbv_lernwelt.core.base import LoggedCommand
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
class Command(LoggedCommand):
|
||||
help = "Simple Dummy Job to test if supercronic is working"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
logger.debug(
|
||||
"Dummy Job finished",
|
||||
label="job_lob",
|
||||
)
|
||||
Loading…
Reference in New Issue