-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlua_reg.py
79 lines (50 loc) · 1.48 KB
/
lua_reg.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*-coding:utf-8 -*
"""
lua_reg.py
register lua files to redis by calling mabo_sv
"""
##
## load lua script
## EVAL -> Register -> Call
import json
import time
from pathlib import Path
from urllib3.exceptions import ConnectionError, NewConnectionError
import redis
import requests
LUA_REG_URL = "http://127.0.0.1:8001/lua/register"
class LuaReg(object):
""""""
def __init__(self):
""""""
self.url = LUA_REG_URL
### self.redis = redis.Redis(host="127.0.0.1", port=6379, db=0)
### z = self.redis.script_flush()
def run(self, fn):
"""run """
base_name = Path(fn).name
key = "_".join(["lua", base_name.split(".")[0]])
with open(fn, "r") as fh:
lua_script = fh.read()
payload = {key: lua_script}
r = requests.post(self.url, data=json.dumps(payload))
result = json.loads(r.text)
print("{}:{}".format(key, result[key]))
### print(lua_script)
print("==" * 20)
def main(lua_pattern: str):
"""reload lua from conf/lua/"""
lua_files = Path().cwd().joinpath("conf", "lua").glob(lua_pattern)
reg = LuaReg()
for fn in lua_files:
try:
reg.run(fn)
pass
except Exception as ex:
print("{} load failed".format(fn))
print(ex)
break
### raise (Exception(repr(ex)))
if __name__ == "__main__":
lua_pattern = "*.lua"
main(lua_pattern)