简体   繁体   中英

django celery for long running task

I have list of players like :

player_list = Participant.objects.all()
participant_count = player_list.count()

I want to randomly select winner from this like:

winner_index = random.randint(0, participant_count-1)
winner = player_list[winner_index]

Lets say I have one million participant then I guess It will take long time to randomly generate winner. Till then my site will be hang I guess.

For this purpose should I use celery or its fine? What if my site go hang for few minutes and only display winner. Any suggestion ?

With proper indexing your database should be able to handle this without needing any special workarounds. If you make it asynchronous with celery, then you won't be able to include that data in your standard request/response cycle.

If you're worried about page speed for the user, you could load a page without the winner, then do an ajax call using javascript to get the winner and update the page, allowing you to display a loading message to the user while they wait.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM