0

I have a problem with my website. there it is :

No problem in this case :

  • User A do a request.
  • Django server update data...
  • Object 1 is updated.
  • Object 2 is updated.
  • Object 3 is updated.
  • Django render the result.
  • User A do a request.

Problem apear in this case :

  • User A do a request.
  • Django server update data...
  • Object 1 is updated.
  • Object 2 is updated.
  • User A do another request !
  • User A do another request !
  • Django render the result.

the problem is that if the user makes a request while the server has not finished working, the server stop the process and data are no longer good.

I think i have to block client side (by displaying a loading message for exemple) but i want to be sur the user cant make a request on the server if another treatemment still working.

thanks for your time.

4

1 回答 1

1

这听起来你有一个长时间运行的进程,用户厌倦了等待,点击浏览器中的“停止”;另一种情况是 - 用户打开另一个选项卡并再次发送相同的请求。

解决这个问题的几种方法。

  1. 如果请求中断,请使用事务中间件来防止您的数据库对象被损坏。

  2. 使用像celery这样的任务队列。在第一次请求时,将您的任务卸载到队列/代理。向用户发送一条消息,表明他们的请求已被接受处理。现在用户可以自由地发送重复请求。如果是这样,您可以检查队列的状态并拒绝重复的请求。

于 2012-10-05T13:41:26.323 回答