diff --git a/compose/django/Dockerfile b/compose/django/Dockerfile index 85e4ba33..0bdccfde 100644 --- a/compose/django/Dockerfile +++ b/compose/django/Dockerfile @@ -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"] diff --git a/compose/django/docker_start.sh b/compose/django/docker_start.sh index 2f359bd2..b6fa79cb 100644 --- a/compose/django/docker_start.sh +++ b/compose/django/docker_start.sh @@ -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 diff --git a/compose/django/send_attendance_course_reminders b/compose/django/send_attendance_course_reminders deleted file mode 100644 index 4d3af4d1..00000000 --- a/compose/django/send_attendance_course_reminders +++ /dev/null @@ -1 +0,0 @@ -@daily /usr/local/bin/python /app/manage.py send_attendance_course_reminders diff --git a/compose/django/sshd_config b/compose/django/sshd_config deleted file mode 100644 index e69de29b..00000000 diff --git a/compose/django/supercronic_crontab b/compose/django/supercronic_crontab new file mode 100644 index 00000000..49452de0 --- /dev/null +++ b/compose/django/supercronic_crontab @@ -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 diff --git a/compose/django/supervisord.conf b/compose/django/supervisord.conf new file mode 100644 index 00000000..2e668f56 --- /dev/null +++ b/compose/django/supervisord.conf @@ -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 diff --git a/server/vbv_lernwelt/core/management/commands/simple_dummy_job.py b/server/vbv_lernwelt/core/management/commands/simple_dummy_job.py new file mode 100644 index 00000000..9d130a52 --- /dev/null +++ b/server/vbv_lernwelt/core/management/commands/simple_dummy_job.py @@ -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", + )