What would be the best way to return the result of asynchronous task to Django views?
I am building a Djano app that processes image in a Celery task. A post inside the view method handles the input and triggers the task. Inside the task, I create a model instance based on the processed image. In the same view, I wanted to return a response of the de-serialization of the model instance. What is the best way to throw this response? Should a frontend expect this on another url? How can I signal my app that the model instance is ready to be served?
# models.py class Image(models.Model): name = models.CharField(max_length=50, blank=True) ... # tasks.py @shared_task def long_running_function(user, data): image = Image.objects.create() ... return image # ? # views.py class RequestImage(APIView): def post(self, request): ... image = celery_task_example.delay( request.user.id, request.data ) # if image is ready serializer = ImageSerializer(image) return Response(serializer.data)