From 62f2ebd24e2dfa9f83b633a156faea1bbfc9ee4d Mon Sep 17 00:00:00 2001 From: andrepapoti Date: Fri, 12 Apr 2024 00:28:43 -0300 Subject: [PATCH] web: add cron service Signed-off-by: andrepapoti --- .../management/commands/update_reviewers.py | 25 +++++++++++++++++++ tools/docker/Dockerfile | 8 ++++++ tools/docker/crontab | 1 + tools/docker/entrypoint.sh | 1 + 4 files changed, 35 insertions(+) create mode 100644 patchwork/management/commands/update_reviewers.py create mode 100644 tools/docker/crontab diff --git a/patchwork/management/commands/update_reviewers.py b/patchwork/management/commands/update_reviewers.py new file mode 100644 index 000000000..0b4862e0f --- /dev/null +++ b/patchwork/management/commands/update_reviewers.py @@ -0,0 +1,25 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2015 Jeremy Kerr +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from django.core.management.base import BaseCommand +from patchwork.models import Patch +from patchwork.api.patch import PatchReviewIntentionSerializer + + +class Command(BaseCommand): + help = 'Updates the patch has_planned_review field' + + def handle(self, *args, **kwargs): + for patch in Patch.objects.all(): + has_planned_review = False + for ( + patch_interest + ) in patch.planning_to_review.through.objects.filter(patch=patch): + serializer = PatchReviewIntentionSerializer(patch_interest) + if not serializer.data['is_stale']: + has_planned_review = True + break + patch.has_planned_review = has_planned_review + patch.save() diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index bdae67a27..eaadd0718 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -31,6 +31,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ sqlite3 \ tzdata \ pkg-config \ + cron \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN pip install wheel tox @@ -40,8 +41,15 @@ RUN pip install wheel tox COPY requirements-dev.txt requirements-test.txt /opt/ RUN pip install -r /opt/requirements-dev.txt +COPY tools/docker/crontab /etc/cron.d/patchwork-cron +RUN crontab -u patchwork /etc/cron.d/patchwork-cron +RUN chmod u+s /usr/sbin/cron +RUN printenv >> /etc/environment + COPY tools/docker/entrypoint.sh /usr/local/bin/entrypoint.sh ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"] USER patchwork WORKDIR /home/patchwork/patchwork + +COPY --chown=patchwork:patchwork . . diff --git a/tools/docker/crontab b/tools/docker/crontab new file mode 100644 index 000000000..f21f80a19 --- /dev/null +++ b/tools/docker/crontab @@ -0,0 +1 @@ +* * * * * /opt/pyenv/shims/python patchwork/manage.py update_reviewers > /proc/1/fd/1 2>&1 diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index c78c0581f..fb5147c40 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -102,4 +102,5 @@ if ! python manage.py migrate sessions --check -v0; then python manage.py loaddata default_projects #> /dev/null fi +cron exec "$@"