This commit is contained in:
aozhiwei 2019-09-12 16:19:21 +08:00
parent 98f18fc666
commit 6f4b2e0f69

View File

@ -1,18 +1,17 @@
# -*- coding: utf-8 -*-
#!/usr/bin/python
import f7
import json
import traceback
import tornado.web
import tornado.ioloop
class _mainHandler(tornado.web.RequestHandler):
def get(self):
self.write(json.dumps({
'errcode': 0,
'errmsg': '',
'healthy': 1,
'max_rundelay': 10
}))
instance()._dispatchRequest(self)
class _App:
_instance = None
@ -24,9 +23,15 @@ class _App:
return cls._instance
def __init__(self):
self._requestHandler = {}
self._app = tornado.web.Application([
(r"/webapp/index[\.]php", _mainHandler),
])
self.registerHandler('Ops', 'selfChecking', self.__selfChecking)
def init(self, log_dir):
f7.udplog.init()
f7.udplog.setLogDirAndCreate(log_dir)
def start(self):
tornado.ioloop.IOLoop.current().start()
@ -37,5 +42,33 @@ class _App:
def callAt(self, when, callback):
tornado.ioloop.IOLoop.current().call_at(when, callback)
def registerHandler(self, c, a, callback):
self._requestHandler[c + '$' + a] = callback
def _dispatchRequest(self, request):
c = request.get_argument('c', '')
a = request.get_argument('a', '')
handler = self._requestHandler.get(c + '$' + a, None)
if not handler:
request.write('')
return
try:
response = handler(lambda param, def_val = '': request.get_argument(param, def_val))
request.write(response)
except Exception as e:
f7.udplog.error('dispatch request ' + str(e))
request.write(json.dumps({
'errcode': 200,
'errmsg': '服务内部错误',
}))
def __selfChecking(self, request):
return json.dumps({
'errcode': 0,
'errmsg': '',
'healthy': 1,
'max_rundelay': 10
})
def instance():
return _App.instance()