diff --git a/patchwork/management/commands/update_reviewers.py b/patchwork/management/commands/update_reviewers.py new file mode 100644 index 00000000..0b4862e0 --- /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 bdae67a2..eaadd071 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 00000000..c3b1a961 --- /dev/null +++ b/tools/docker/crontab @@ -0,0 +1,6 @@ +DATABASE_HOST=db +DATABASE_PORT=3306 +DATABASE_NAME=patchwork +DATABASE_USER=patchwork +DATABASE_PASSWORD=password +* * * * * /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 c78c0581..fb5147c4 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 "$@"