简体   繁体   English

多个使用者和单个数据源的设计模式

[英]Design pattern for multiple consumers and a single data source

I am designing a web interface to a certain hardware appliance that provides its own custom API. 我正在为某个提供自己的自定义API的硬件设备设计Web界面。 Said web interface can manage multiple appliances at once. 所述web界面可以一次管理多个设备。 The data is retrieved from appliance through polling with the custom API so it'd be preferable to make it asynchronous. 通过使用自定义API进行轮询,可以从设备中检索数据,因此最好使其异步。

The most obvious thing is to have a poller thread that polls for data, saves into a process wide singleton with semaphores and then the web server threads will retrieve data from said singleton and show it. 最明显的是有一个轮询数据的轮询线程,保存到具有信号量的进程范围的单例中,然后Web服务器线程将从所述单例中检索数据并显示它。 I'm not a huge fan of singletons or mashed together designs, so I was thinking of maybe separating the poller datasource from the web server, looping it back on the local interface and using something like XML-RPC to consume data. 我不是单身人士或混合设计的忠实粉丝,所以我想可能将轮询器数据源与Web服务器分离,将其循环回本地接口并使用XML-RPC等消耗数据。

The application need not be 'enterprisey' or scalable really since it'll at most be accessed by a couple people at a time, but I'd rather make it robust by not mixing two kinds of logic together. 该应用程序不一定是'enterprisey'或可扩展的,因为它一次最多只能被几个人访问,但我宁愿通过不将两种逻辑混合在一起来使其变得健壮。 There's a current implementation in python using CherryPy and it's the biggest mishmash of terrible design I've ever seen. 在使用CherryPy的python中有一个当前的实现,它是我见过的最糟糕的糟糕设计混搭。 I feel that if I go with the most obvious design I'll just end up reimplementing the same horrible thing my own way. 我觉得如果我选择最明显的设计,我最终会以自己的方式重新实现同样可怕的事情。

If you use Django and celery , you can create a Django project to be the web interface and a celery job to run in the background and poll. 如果您使用Djangocelery ,您可以创建一个Django项目作为Web界面和芹菜作业在后台运行并进行轮询。 In that job, you can import your Django models so it can save the results of the polling very simply. 在这项工作中,您可以导入Django模型,这样可以非常简单地保存轮询结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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