Django Celery:任务不更新数据库

时间:2015-10-19 05:39:46

标签: python django celery

我有使用芹菜的django app,

@task(name="execute_java_task")
def execute_java_task(solution_id, stdin=None, stdout=None):
    logger.info("Task started")
    s = Solution.objects.get(pk=solution)
    s.solved = True
    s.save()

当用户提交表单时调用此任务

@login_required
def submit(request, question_id):
    form = SolutionForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        f = form.save(commit=False)
        f.user_id = request.user
        f.question_id = get_object_or_404(Question, 
                                          pk=question_id)

        # Checks if the user is re-submitting a solved question.
        rows = Solution.objects.filter(user_id=request.user,
                                       question_id=question_id)
        for row in rows:
            if row.solved:
                messages.success(request, "You have already solved this question.")
                return redirect('index')

        latest_id = Solution.objects.latest('id').id
        if f.language == 'cpp':
            execute_cpp_task.delay(latest_id+1)
        else:
            execute_java_task.delay(latest_id+1)


        f.save()
        messages.success(request, "Submitted successfully")
        return redirect('index')
    return render(request, 'main/form.html', {'form': form})

但是数据库没有得到更新。 这是芹菜工人信息 - [link]

0 个答案:

没有答案