部分优化

This commit is contained in:
aozhiwei 2019-01-24 17:56:45 +08:00
parent f4c7928fed
commit 16308b9303
3 changed files with 14 additions and 9 deletions

View File

@ -2,5 +2,6 @@
"listen_port": 10001, "listen_port": 10001,
"notify_url": "https://kefu-test.kingsome.cn/webapp/index.php?c=Kefu&a=sendMsgAllUser", "notify_url": "https://kefu-test.kingsome.cn/webapp/index.php?c=Kefu&a=sendMsgAllUser",
"sendtime1": 32400, "sendtime1": 32400,
"sendtime2": 64800 "sendtime2": 64800,
"sendtime3": 0
} }

View File

@ -25,12 +25,14 @@ def getDaySeconds(time_val, incdays):
def sendNotify(conf, sendtime): def sendNotify(conf, sendtime):
try: try:
req = urllib.request.Request(conf['notify_url']) url = conf['notify_url']
req = urllib.request.Request(url)
data = urllib.request.urlopen(req).readall() data = urllib.request.urlopen(req).readall()
except: except:
pass pass
#进入下一次循环 #进入下一次循环
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 0) + sendtime, tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + sendtime,
lambda : sendNotify(conf, sendtime)) lambda : sendNotify(conf, sendtime))
class SelfCheckingHandler(tornado.web.RequestHandler): class SelfCheckingHandler(tornado.web.RequestHandler):
@ -49,12 +51,14 @@ def make_app():
]) ])
if __name__ == "__main__": if __name__ == "__main__":
conf = json.loads(open('config/kefu_robot.json', 'r').read()) conf = json.loads(open('../config/kefu_robot.json', 'r').read())
app = make_app() app = make_app()
app.listen(conf['listen_port']) app.listen(conf['listen_port'])
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 0) + conf['sendtime1'], tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime1'],
lambda : sendNotify(conf, conf['sendtime1'])) lambda : sendNotify(conf, conf['sendtime1']))
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 0) + conf['sendtime2'], tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime2'],
lambda : sendNotify(conf, conf['sendtime2'])) lambda : sendNotify(conf, conf['sendtime2']))
tornado.ioloop.IOLoop.current().call_at(time.time() + 3,
lambda : sendNotify(conf, 30))
tornado.ioloop.IOLoop.current().start() tornado.ioloop.IOLoop.current().start()

View File

@ -408,8 +408,8 @@ class KefuController {
public function sendMsgAllUser() public function sendMsgAllUser()
{ {
#error_log('sendMsgAllUser:'); error_log('sendMsgAllUser:');
#error_log('request:' . json_encode($_REQUEST['xxx']));
$mysqls = $this->getAllMysql(); $mysqls = $this->getAllMysql();
foreach($mysqls as $mysql_conf) { foreach($mysqls as $mysql_conf) {
$conn = $this->getAppointMysql($mysql_conf); $conn = $this->getAppointMysql($mysql_conf);
@ -562,7 +562,7 @@ class KefuController {
$r = $this->getRedis($accountid); $r = $this->getRedis($accountid);
$access_token = $r->get('kf_token:' . $accountid . ':'); $access_token = $r->get('kf_token:' . $accountid . ':');
##error_log('acc_token:' . $access_token); #error_log('acc_token:' . $access_token);
if (!empty($access_token)) { if (!empty($access_token)) {
return $access_token; return $access_token;
} }