Avoid passing models to celery tasks

This commit is contained in:
Quantum 2022-02-26 21:27:06 -05:00 committed by Roger Fu
parent 30a2f3b092
commit 0a8e3cfe54
2 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,5 @@
from celery import shared_task
from django.contrib.auth.models import User
from django.core.cache import cache
from django.utils import timezone
from django.utils.translation import gettext as _
@ -23,9 +24,10 @@ def apply_submission_filter(queryset, id_range, languages, results):
@shared_task(bind=True)
def rejudge_problem_filter(self, problem_id, id_range=None, languages=None, results=None, user=None):
def rejudge_problem_filter(self, problem_id, id_range=None, languages=None, results=None, user_id=None):
queryset = Submission.objects.filter(problem_id=problem_id)
queryset = apply_submission_filter(queryset, id_range, languages, results)
user = User.objects.get(id=user_id)
rejudged = 0
with Progress(self, queryset.count()) as p:

View File

@ -90,7 +90,8 @@ class BaseRejudgeSubmissionsView(PermissionRequiredMixin, ManageProblemSubmissio
class RejudgeSubmissionsView(BaseRejudgeSubmissionsView):
def generate_response(self, id_range, languages, results):
status = rejudge_problem_filter.delay(self.object.id, id_range, languages, results, user=self.request.user)
status = rejudge_problem_filter.delay(self.object.id, id_range, languages, results,
user_id=self.request.user.id)
return redirect_to_task_status(
status, message=_('Rejudging selected submissions for %s...') % (self.object.name,),
redirect=reverse('problem_submissions_rejudge_success', args=[self.object.code, status.id]),