From 90b09101bd224f0bc9c81ae2f58f1184f0eaffde Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 6 May 2020 17:51:11 +0800 Subject: [PATCH] 1 --- .gitigonre | 1 + third_party/f7 | 1 + third_party/q7 | 1 + tools/kefu_robot.py | 104 +++++++++++------- tools/local_packages/f7 | 1 + tools/local_packages/q7 | 1 + tools/nohup.out | 15 --- .../controller/SubscribeController.class.php | 4 +- 8 files changed, 70 insertions(+), 58 deletions(-) create mode 160000 third_party/f7 create mode 160000 third_party/q7 create mode 120000 tools/local_packages/f7 create mode 120000 tools/local_packages/q7 delete mode 100644 tools/nohup.out diff --git a/.gitigonre b/.gitigonre index 48d6438..679dec1 100644 --- a/.gitigonre +++ b/.gitigonre @@ -8,3 +8,4 @@ *.tar.gz config .idea +nohup.out \ No newline at end of file diff --git a/third_party/f7 b/third_party/f7 new file mode 160000 index 0000000..d84f116 --- /dev/null +++ b/third_party/f7 @@ -0,0 +1 @@ +Subproject commit d84f1162556e1703d71a203cc2985d61bafea32e diff --git a/third_party/q7 b/third_party/q7 new file mode 160000 index 0000000..4af43d5 --- /dev/null +++ b/third_party/q7 @@ -0,0 +1 @@ +Subproject commit 4af43d56490d566c38021d9687975dae17d9e7ad diff --git a/tools/kefu_robot.py b/tools/kefu_robot.py index c30b02a..b0a7e2a 100644 --- a/tools/kefu_robot.py +++ b/tools/kefu_robot.py @@ -1,5 +1,11 @@ # -*- coding: utf-8 -*- + +import sys +sys.path.append('./local_packages') +import q7 +import f7 + import os import json import time @@ -9,6 +15,7 @@ import urllib.request import tornado.ioloop import tornado.web + def md5Sign(params, secret, timestamp, connstr = '&', secret_connstr = ':'): params_str = '' for key in sorted(params.keys()): @@ -44,9 +51,18 @@ def sendNotify(conf, sendtime): except Exception as e: print('sendNotifu error: ' + str(e), flush=True) - #进入下一次循环 - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + sendtime, - lambda : sendNotify(conf, sendtime)) +#进入下一次循环 +def _sendNotify(conf, sendtime): + if f7.app.ext['sendNotify']: + f7.timer.callAt(getDaySeconds(time.time(), 1) + sendtime, + lambda : _sendNotify(conf, sendtime)) + return + def donekefu_callback(): + f7.app.ext['sendNotify'] = False + f7.timer.callAt(getDaySeconds(time.time(), 1) + sendtime, + lambda : _sendNotify(conf, sendtime)) + f7.app.ext['sendNotify'] = True + f7.app.createAsyncTask(donekefu_callback, sendNotify(conf, sendtime), (conf, sendtime)) def sendOrderNotify(conf, sendtime): try: @@ -64,48 +80,54 @@ def sendOrderNotify(conf, sendtime): print('sendOrderNotify error: ' + str(e), flush=True) #进入下一次循环 - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + sendtime, - lambda : sendOrderNotify(conf, sendtime)) +def _sendOrderNotify(conf, sendtime): + if f7.app.ext['sendOrder']: + f7.timer.callAt(getDaySeconds(time.time(), 1) + sendtime, + lambda : _sendOrderNotify(conf, sendtime)) + return + def doneorder_callback(): + f7.app.ext['sendOrder'] = False + f7.timer.callAt(getDaySeconds(time.time(), 1) + sendtime, + lambda : _sendOrderNotify(conf, sendtime)) + f7.app.ext['sendOrder'] = True + f7.app.createAsyncTask(doneorder_callback, sendOrderNotify, (conf, sendtime)) -class SelfCheckingHandler(tornado.web.RequestHandler): - - def get(self): - self.write(json.dumps({ - 'errcode': 0, - 'errmsg': '', - 'healthy': 1, - 'max_rundelay': 10 - }, - separators=(',', ':'))) - -def make_app(): - return tornado.web.Application([ - (r"/webapp/index[\.]php", SelfCheckingHandler), - ]) +def test(request): + conf = json.loads(open('../config/kefu_robot.json', 'r').read()) + _sendOrderNotify(conf, conf['signtime']) + return '{"error_code":0, "error_msg":""}' if __name__ == "__main__": print('start!', flush=True) + q7.xPrint('pid %d' % os.getpid()) + f7.app.init('/data/logs/kefu_robot/logs') + f7.udplog.info('kefu_robot start pid:' + str(os.getpid())) + + f7.app.ext['sendOrder'] = False + f7.app.ext['sendNotify'] = False conf = json.loads(open('../config/kefu_robot.json', 'r').read()) - app = make_app() - app.listen(conf['listen_port']) - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime1'], - lambda : sendNotify(conf, conf['sendtime1'])) - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime2'], - lambda : sendNotify(conf, conf['sendtime2'])) - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime3'], - lambda : sendNotify(conf, conf['sendtime3'])) + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['sendtime1'], + lambda : _sendNotify(conf, conf['sendtime1'])) + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['sendtime2'], + lambda : _sendNotify(conf, conf['sendtime2'])) + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['sendtime3'], + lambda : _sendNotify(conf, conf['sendtime3'])) + + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['signtime'], + lambda : _sendOrderNotify(conf, conf['signtime'])) + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['boxtime'], + lambda : _sendOrderNotify(conf, conf['boxtime'])) + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['diamondtime1'], + lambda : _sendOrderNotify(conf, conf['diamondtime1'])) + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['diamondtime2'], + lambda : _sendOrderNotify(conf, conf['diamondtime2'])) + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['diamondtime3'], + lambda : _sendOrderNotify(conf, conf['diamondtime3'])) + f7.timer.callAt(getDaySeconds(time.time(), 1) + conf['seasontime'], + lambda : _sendOrderNotify(conf, conf['seasontime'])) + f7.app.listen(conf['listen_port']) + f7.app.registerHandler('Ops', 'test', test) + f7.app.start() + - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['signtime'], - lambda : sendOrderNotify(conf, conf['signtime'])) - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['boxtime'], - lambda : sendOrderNotify(conf, conf['boxtime'])) - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['diamondtime1'], - lambda : sendOrderNotify(conf, conf['diamondtime1'])) - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['diamondtime2'], - lambda : sendOrderNotify(conf, conf['diamondtime2'])) - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['diamondtime3'], - lambda : sendOrderNotify(conf, conf['diamondtime3'])) - tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['seasontime'], - lambda : sendOrderNotify(conf, conf['seasontime'])) - tornado.ioloop.IOLoop.current().start() diff --git a/tools/local_packages/f7 b/tools/local_packages/f7 new file mode 120000 index 0000000..ba67c55 --- /dev/null +++ b/tools/local_packages/f7 @@ -0,0 +1 @@ +../../third_party/f7/f7 \ No newline at end of file diff --git a/tools/local_packages/q7 b/tools/local_packages/q7 new file mode 120000 index 0000000..55bf44e --- /dev/null +++ b/tools/local_packages/q7 @@ -0,0 +1 @@ +../../third_party/q7/q7 \ No newline at end of file diff --git a/tools/nohup.out b/tools/nohup.out deleted file mode 100644 index 6b8de20..0000000 --- a/tools/nohup.out +++ /dev/null @@ -1,15 +0,0 @@ -start! -1588176000 -1588176000 -1588176000 -1588176000 -1588176000 -1588176000 -2020-04-30 08:00:1588204800 -sendNotifySubscribe start -sendNotify end -1588262400 -2020-04-30 09:00:1588208400 -sendNotifySubscribe start -sendNotify end -1588262400 diff --git a/webapp/controller/SubscribeController.class.php b/webapp/controller/SubscribeController.class.php index 2c83fb7..13d15e6 100644 --- a/webapp/controller/SubscribeController.class.php +++ b/webapp/controller/SubscribeController.class.php @@ -131,7 +131,7 @@ class SubscribeController { $data = array(); $date = phpcommon\timestamp_to_datetime(time()); //通知签到 - if (floor((time() - phpcommon\getdayseconds(time())) / 3600) == 8) { + if (floor((time() - phpcommon\getdayseconds(time())) / 3600) == 17) { while (true) { $rows = $conn->execQuery('SELECT idx, accountid, openid, signtime ' . ' FROM subscribe WHERE signorder=1 AND idx > :last_idx LIMIT 0, 1000;', @@ -145,7 +145,7 @@ class SubscribeController { if ($row['idx'] > $last_idx) { $last_idx = $row['idx']; } - if (floor((time() - phpcommon\getdayseconds($row['signtime'])) / 3600) != 32) { + if (floor((time() - phpcommon\getdayseconds($row['signtime'])) / 3600) != 17) { continue; } $data = array(