This commit is contained in:
aozhiwei 2020-05-06 17:51:11 +08:00
parent 00818ecfea
commit 90b09101bd
8 changed files with 70 additions and 58 deletions

View File

@ -8,3 +8,4 @@
*.tar.gz
config
.idea
nohup.out

1
third_party/f7 vendored Submodule

@ -0,0 +1 @@
Subproject commit d84f1162556e1703d71a203cc2985d61bafea32e

1
third_party/q7 vendored Submodule

@ -0,0 +1 @@
Subproject commit 4af43d56490d566c38021d9687975dae17d9e7ad

View File

@ -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()

1
tools/local_packages/f7 Symbolic link
View File

@ -0,0 +1 @@
../../third_party/f7/f7

1
tools/local_packages/q7 Symbolic link
View File

@ -0,0 +1 @@
../../third_party/q7/q7

View File

@ -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

View File

@ -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(