forked from crazzle/PyPoSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyPoSim.py
40 lines (34 loc) · 1.39 KB
/
PyPoSim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
from tornado import ioloop, web
from pykka import ActorRegistry
from actor import PlantRegistry
from handler import Handler
import util.Config as Config
import datasinks.LoggingSink as LoggingSink
import datasinks.KafkaSink as KafkaSink
def tell_tick():
ActorRegistry.broadcast({'msg': 'tick'})
if __name__ == '__main__':
## configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("tornado.application")
logger.info("starting application PyPoSim...")
## adding standard plant
if Config.get_startup_config()["add_default_plant"]:
PlantRegistry.add_new_plant("Default", 100, 10, 5)
## register datasinks
if Config.get_kafka_config()["enabled"]:
KafkaSink.subscribe()
if Config.get_history_config()["enabled"]:
logger.info("history enabled")
LoggingSink.subscribe()
app = web.Application([("/", Handler.AllPlants),
("/add", Handler.Add),
(r"/([a-zA-Z0-9]{2,})", Handler.Stats),
(r"/masterdata/([a-zA-Z0-9]{2,})", Handler.MasterData),
(r"/dispatch/([a-zA-Z0-9]{2,})/(\d+)", Handler.Dispatch),
(r"/delete/([a-zA-Z0-9]{2,})", Handler.Delete)])
app.listen(5000)
loop = ioloop.IOLoop.current()
ioloop.PeriodicCallback(tell_tick,1000).start()
loop.start()