Skip to content

Commit d9abfce

Browse files
andrepapotivictor-accarini
authored andcommitted
web: add cron service to update 'has_planned_review' field on patches
Signed-off-by: andrepapoti <[email protected]>
1 parent ee44418 commit d9abfce

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Patchwork - automated patch tracking system
2+
# Copyright (C) 2015 Jeremy Kerr <[email protected]>
3+
#
4+
# SPDX-License-Identifier: GPL-2.0-or-later
5+
6+
from django.core.management.base import BaseCommand
7+
from patchwork.models import Patch
8+
from patchwork.api.patch import PatchReviewIntentionSerializer
9+
10+
11+
class Command(BaseCommand):
12+
help = 'Updates the patch has_planned_review field'
13+
14+
def handle(self, *args, **kwargs):
15+
for patch in Patch.objects.all():
16+
has_planned_review = False
17+
for (
18+
patch_interest
19+
) in patch.planning_to_review.through.objects.filter(patch=patch):
20+
serializer = PatchReviewIntentionSerializer(patch_interest)
21+
if not serializer.data['is_stale']:
22+
has_planned_review = True
23+
break
24+
patch.has_planned_review = has_planned_review
25+
patch.save()

tools/docker/Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2525
sqlite3 \
2626
tzdata \
2727
pkg-config \
28+
cron \
2829
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
2930

3031
RUN pip install wheel tox
@@ -34,8 +35,15 @@ RUN pip install wheel tox
3435
COPY requirements-dev.txt requirements-test.txt /opt/
3536
RUN pip install -r /opt/requirements-dev.txt
3637

38+
COPY tools/docker/crontab /etc/cron.d/patchwork-cron
39+
RUN crontab -u patchwork /etc/cron.d/patchwork-cron
40+
RUN chmod u+s /usr/sbin/cron
41+
RUN printenv >> /etc/environment
42+
3743
COPY tools/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
3844
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
3945
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
4046
USER patchwork
4147
WORKDIR /home/patchwork/patchwork
48+
49+
COPY --chown=patchwork:patchwork . .

tools/docker/crontab

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DATABASE_HOST=db
2+
DATABASE_PORT=3306
3+
DATABASE_NAME=patchwork
4+
DATABASE_USER=patchwork
5+
DATABASE_PASSWORD=password
6+
0 * * * * /opt/pyenv/shims/python patchwork/manage.py update_reviewers > /proc/1/fd/1 2>&1

tools/docker/entrypoint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ if ! python manage.py migrate sessions --check -v0; then
102102
python manage.py loaddata default_projects #> /dev/null
103103
fi
104104

105+
cron
105106
exec "$@"

0 commit comments

Comments
 (0)