Skip to content

Commit

Permalink
web: add cron service to update 'has_planned_review' field on patches
Browse files Browse the repository at this point in the history
Signed-off-by: andrepapoti <[email protected]>
  • Loading branch information
andrepapoti committed Apr 17, 2024
1 parent 909fb55 commit 1001da9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions patchwork/management/commands/update_reviewers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Patchwork - automated patch tracking system
# Copyright (C) 2015 Jeremy Kerr <[email protected]>
#
# 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()
8 changes: 8 additions & 0 deletions tools/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 . .
6 changes: 6 additions & 0 deletions tools/docker/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DATABASE_HOST=db
DATABASE_PORT=3306
DATABASE_NAME=patchwork
DATABASE_USER=patchwork
DATABASE_PASSWORD=password
0 * * * * /opt/pyenv/shims/python patchwork/manage.py update_reviewers > /proc/1/fd/1 2>&1
1 change: 1 addition & 0 deletions tools/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ if ! python manage.py migrate sessions --check -v0; then
python manage.py loaddata default_projects #> /dev/null
fi

cron
exec "$@"

0 comments on commit 1001da9

Please sign in to comment.