diff --git a/Main/management/commands/loop.py b/Main/management/commands/loop.py new file mode 100644 index 0000000..ded4ddd --- /dev/null +++ b/Main/management/commands/loop.py @@ -0,0 +1,21 @@ +import datetime +from time import sleep + +from django.core.management.base import BaseCommand +from django.utils import timezone + +from Checker.models import Checker + + +class Command(BaseCommand): + help = "starts loop" + + def check_checkers(self): + for checker in Checker.objects.filter(testing_solution__isnull=False, last_request__lt=timezone.now() - datetime.timedelta(seconds=3)): + checker.testing_solution.result = 'In queue' + checker.testing_solution.save() + + def handle(self, *args, **options): + while True: + self.check_checkers() + sleep(5) diff --git a/Main/views/SolutionsView.py b/Main/views/SolutionsView.py index 6f2b948..093c800 100644 --- a/Main/views/SolutionsView.py +++ b/Main/views/SolutionsView.py @@ -12,4 +12,7 @@ class SolutionsView(BaseView): queries.append('task_id=' + self.request.GET['task_id']) if 'set_id' in self.request.GET.keys(): queries.append('set_id=' + self.request.GET['set_id']) + self.context['in_set'] = True + else: + self.context['in_set'] = False self.context['query'] = '&'.join(queries) diff --git a/docker-compose.yaml b/docker-compose.yaml index d30488f..ed9d4f7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -55,6 +55,15 @@ services: depends_on: - web + loop: + image: mathwave/sprint-repo:sprint + restart: always + environment: + HOST: $HOST + command: ./manage.py loop + depends_on: + - web + rabbitmq: restart: always build: @@ -101,3 +110,4 @@ services: - bot - postgres - apply-languages + - loop diff --git a/templates/solutions.html b/templates/solutions.html index 9dc788a..362c3a3 100644 --- a/templates/solutions.html +++ b/templates/solutions.html @@ -23,7 +23,7 @@ {% block onload %}doPoll(){% endblock %} {% block main %} -