A
A
Andrei1penguin12021-10-18 15:25:29
Django
Andrei1penguin1, 2021-10-18 15:25:29

Why save results in Celery?

Good day, I don’t quite understand why we need to save the results in Celery Let
’s say we need to add a post to the page, when we receive an ajax request, we entrust this task to Celery and immediately return httpresponse("") in the view
After adding the publication, we don’t need anything else
Probably my misunderstanding is caused by the fact that the result of the task actually represents.
Please tell me this moment and why it needs to be saved (or not needed, what should be more productive)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2021-10-18
@Andrei1penguin1

Well, using Celery to add a post is an overkill. In general, the point is that the http request handler should respond to the request as quickly as possible and complete the work. Concurrency in Django, as in many other frameworks, is provided by running multiple processes. If the response request handler needs, for example, one second and three processes are running, then the service is able to process no more than three requests per second. If there are ten times more requests, then some of them will have to hang on loading for ten seconds and maybe even fall off on a timeout. If there are many processes to run, then there will be a high consumption of server resources. So it's reasonable to queue anything that potentially takes more than 100 milliseconds to be processed in the background.

A
Alexander Nesterov, 2021-10-18
@AlexNest

The bottom line is that tasks in the queue run asynchronously and won't break the logic that goes on if something happens.
1. For example - registration on the site occurs synchronously, for example, if the mail service from which registration letters are sent falls down, then the view will most likely break (in general, it can be processed as an error by an exception, but it can be so).
2. The mail service can think for a long time and until it sends the same letter, the view will "hang". Therefore, tasks that may take some time (including writing to the database) are also run asynchronously.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question