Reputation: 110143
If I have the following code:
$('#do-updates').click(function() {
$.post('/do_updates/',
function(response){
location.reload();
});
});
And the python function it calls is:
def do_update():
for item in items:
do something
The python function I call takes about 2m to finish.
If a user does the following:
1 - Click on the #do-updates button
2 - Navigate away from the page after 10s
What will happen? Will the entire do_updates()
function run, because it is called asynchronously? Or will that function time out? If it does timeout, what's a better way to do the do_updates()
function in the background so it will finish?
Upvotes: 3
Views: 247
Reputation: 522
If you dont need result of do_something on frontend you can use some of asynchronus task solution. Celery is probably most popular and simple to use with django. It delegates work to dedicated worker which is running as different process through messaging queue(rabbitmq, redis, ..).
Upvotes: 2