Junior
Feedback processing
livecode
Task condition
In the API controller, a Feedback object is created, after which the change_status_feedback task is called asynchronously. The task changes the feedback status, sends an email, and saves the object.
Check:
- Is it possible to pass the entire feedback object to the Celery task (or is it better to pass the id)?
- Will there be serialization issues with the feedback object?
- How does send_mail() work — does it block execution, are there exceptions?
- Is it guaranteed that feedback.save() will complete successfully after sending the email?
- Is the in_progress status set correctly?
@app.task(name='change_status_feedback')
def change_status_feedback(feedback):
feedback.status = 'in_progress'
send_mail()
feedback.save()
class CreateFeedbackAPIView(APIView):
def create(self, request):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
feedback = Feedback.objects.create(**serializer.validated_data)
change_status_feedback.delay(feedback)
return feedback