V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wdg8106
V2EX  ›  Python

商城提交一个订单,在后台管理页面收到订单提示,这种逻辑大家是怎么做的呢

  •  
  •   wdg8106 · 2016-03-07 11:32:53 +08:00 · 5535 次点击
    这是一个创建于 2979 天前的主题,其中的信息可能已经有所发展或是发生改变。
    后台框架用的 tornado ,之前做的是轮询,在后台管理页面不断的用 js 发送请求,当数据库订单数发生变化时弹出一个提示消息


    这种业务逻辑用 websockets 怎么实现呢,或者还有什么其它更好的方法呢
    5 条回复    2016-03-08 16:17:10 +08:00
    996635
        1
    996635  
       2016-03-07 17:44:45 +08:00   ❤️ 1
    用 ws 实现一样的,只是轮询从前端放到了后端.
    另外还可以考虑 类似 redis subscribe 的方式阻塞链接,避免轮询.
    cevincheung
        2
    cevincheung  
       2016-03-08 01:26:59 +08:00   ❤️ 1
    还是轮询的好。
    只要有新订单通知过一次,没操作之前就不再轮询了。
    wdg8106
        3
    wdg8106  
    OP
       2016-03-08 07:48:42 +08:00
    @996635 后端的轮询是指每隔一段时间 后端查询是否有新订单然后调用 write_message ,把消息发送到管理页面么
    wdg8106
        4
    wdg8106  
    OP
       2016-03-08 07:54:19 +08:00
    @cevincheung 嗯,这样就解决了不停的弹出消息框提示的问题,
    wdg8106
        5
    wdg8106  
    OP
       2016-03-08 16:17:10 +08:00
    @wdg8106 我在服务器上使用 websockets 会报这样一个错误 :
    WebSocket connection to 'ws://test.senguo.cc/admin/realtime' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

    引发出错的 js 代码是: var ws = new WebSocket("ws:test.senguo.cc/admin/realtime");

    但是在本地测试的时候是正常的,请教下你知道是什么原因嘛~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1730 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:37 · PVG 08:37 · LAX 17:37 · JFK 20:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.