Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openresty
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tangku7
openresty
Commits
c5379d91
Commit
c5379d91
authored
Sep 17, 2018
by
周尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize ngx resolver
parent
15d0a2a9
Changes
27
Show whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
266 additions
and
190 deletions
+266
-190
nginx/conf/nginx.conf
nginx/conf/nginx.conf
+8
-12
nginx/lua/luabiz/async.lua
nginx/lua/luabiz/async.lua
+64
-60
nginx/lua/luabiz/node_asb.lua
nginx/lua/luabiz/node_asb.lua
+1
-1
nginx/lua/luabiz/node_asbdetail.lua
nginx/lua/luabiz/node_asbdetail.lua
+1
-1
nginx/lua/luabiz/node_card.lua
nginx/lua/luabiz/node_card.lua
+22
-21
nginx/lua/luabiz/node_chgrule.lua
nginx/lua/luabiz/node_chgrule.lua
+1
-1
nginx/lua/luabiz/node_cs.lua
nginx/lua/luabiz/node_cs.lua
+1
-1
nginx/lua/luabiz/node_csdetail.lua
nginx/lua/luabiz/node_csdetail.lua
+1
-1
nginx/lua/luabiz/node_ms.lua
nginx/lua/luabiz/node_ms.lua
+1
-1
nginx/lua/luabiz/node_payment.lua
nginx/lua/luabiz/node_payment.lua
+1
-1
nginx/lua/luabiz/node_psb.lua
nginx/lua/luabiz/node_psb.lua
+1
-1
nginx/lua/luabiz/node_psbdetail.lua
nginx/lua/luabiz/node_psbdetail.lua
+1
-1
nginx/lua/luabiz/node_rchg.lua
nginx/lua/luabiz/node_rchg.lua
+1
-1
nginx/lua/luabiz/node_rchgdetail.lua
nginx/lua/luabiz/node_rchgdetail.lua
+1
-1
nginx/lua/luabiz/node_saledetail.lua
nginx/lua/luabiz/node_saledetail.lua
+1
-1
nginx/lua/luabiz/node_saleorder.lua
nginx/lua/luabiz/node_saleorder.lua
+1
-1
nginx/lua/luabiz/node_shift.lua
nginx/lua/luabiz/node_shift.lua
+1
-1
nginx/lua/luabiz/node_sku.lua
nginx/lua/luabiz/node_sku.lua
+1
-1
nginx/lua/luabiz/node_sms.lua
nginx/lua/luabiz/node_sms.lua
+1
-1
nginx/lua/luabiz/node_smsvip.lua
nginx/lua/luabiz/node_smsvip.lua
+1
-1
nginx/lua/luabiz/node_ticket.lua
nginx/lua/luabiz/node_ticket.lua
+22
-23
nginx/lua/luabiz/node_vipacct.lua
nginx/lua/luabiz/node_vipacct.lua
+1
-1
nginx/lua/luabiz/settle.lua
nginx/lua/luabiz/settle.lua
+35
-51
nginx/lua/luabiz/tk_sdt.lua
nginx/lua/luabiz/tk_sdt.lua
+2
-2
nginx/lua/luabiz/tk_sync.lua
nginx/lua/luabiz/tk_sync.lua
+2
-2
nginx/lua/luabiz/zx_base.lua
nginx/lua/luabiz/zx_base.lua
+54
-1
nginx/lua/luainit/init.lua
nginx/lua/luainit/init.lua
+39
-0
No files found.
nginx/conf/nginx.conf
View file @
c5379d91
...
...
@@ -38,6 +38,7 @@ http {
init_by_lua_file
"lua/luainit/init.lua"
;
init_worker_by_lua_file
"lua/luabiz/settle.lua"
;
#gzip on;
server
{
listen
8080
;
...
...
@@ -68,8 +69,8 @@ http {
location
/
{
root
html
;
index
index.html
index.htm
;
root
/Users/zhoush/Documents/Private/Notes/
;
index
README.html
;
lua_code_cache
on
;
log_by_lua_block
{
local
logger
=
require("socket")
...
...
@@ -96,16 +97,11 @@ http {
}
}
location
/
regex
{
location
/
get_addr
{
content_by_lua_block
{
local
str
=
'2018-08-15'
local
regex
=
[[(
\
d+)-(
\
d+)-(
\
d+)]]
local
r
=
ngx.re.match(str,
regex,
'jo')
if
r
then
ngx.say(r[1],
r[2],
r[3])
else
ngx.say('no
matched')
end
local
zx_base
=
loadmod("zx_base")
local
host
=
zx_base:_get_addr("www.baidu.com")
ngx.say(host)
}
}
...
...
nginx/lua/luabiz/async.lua
View file @
c5379d91
...
...
@@ -5,68 +5,72 @@ local mysql = loadmod("resty.mysql")
local
json
=
loadmod
(
'cjson'
)
local
zx_base
=
loadmod
(
'zx_base'
)
local
function
async_sql_ins
()
local
pay_type
local
rate
=
305
local
reqs
=
json
.
decode
(
ngx
.
var
.
request_body
)
if
reqs
[
"code"
]
~=
"SUCCESS"
then
return
nil
end
if
string.find
(
reqs
[
"trade_type"
],
"alipay"
)
then
pay_type
=
"12"
elseif
string.find
(
reqs
[
"trade_type"
],
"weixin"
)
then
pay_type
=
"11"
end
local
ins_sql
=
string.format
(
[[INSERT INTO pay_noty_trace SET host_map_id = 3, tkpay_order_no = %d, channel_order_no = %s, host_order_no = %s,
pay_type = %s, trans_amt = %s, trans_time = %s, trans_status = %s, currency = '%s', rate = %d]]
,
reqs
[
'out_transaction_no'
],
reqs
[
'out_trade_no'
],
reqs
[
'transaction_no'
],
pay_type
,
reqs
[
'total_amount'
]
*
100
,
reqs
[
'time_start'
],
"0"
,
reqs
[
'currency'
],
rate
)
zx_base
:
log
(
"ASYNC_SQL"
,
ins_sql
)
return
ins_sql
end
local
function
async_db
(
ins_sql
)
local
db
,
err
=
mysql
:
new
()
if
not
db
then
zx_base
:
log
(
"ASYNC_DB"
,
"failed to instantiate mysql: "
,
err
)
return
false
end
db
:
set_timeout
(
1000
)
-- 1 sec
local
db_st
=
zx_base
:
db_read
()
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
password
=
db_st
[
'password'
],
timeout
=
db_st
[
'timeout'
],
charset
=
'utf8'
}
if
not
ok
then
zx_base
:
log
(
"ASYNC_DB"
,
err
,
": "
,
errcode
,
" "
,
sqlstate
)
return
end
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
ins_sql
)
if
not
res
then
zx_base
:
log
(
"ASYNC_DB"
,
"bad result: "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
end
db
:
set_keepalive
(
10000
,
100
)
end
--
local function async_sql_ins()
--
local pay_type
--
local rate = 305
--
local reqs = json.decode(ngx.var.request_body)
--
if reqs["code"] ~= "SUCCESS" then
--
return nil
--
end
--
if string.find(reqs["trade_type"], "alipay") then
--
pay_type = "12"
--
elseif string.find(reqs["trade_type"], "weixin") then
--
pay_type = "11"
--
end
--
local ins_sql = string.format(
--
[[INSERT INTO pay_noty_trace SET host_map_id = 3, tkpay_order_no = %d, channel_order_no = %s, host_order_no = %s,
--
pay_type = %s, trans_amt = %s, trans_time = %s, trans_status = %s, currency = '%s', rate = %d]],
--
reqs['out_transaction_no'], reqs['out_trade_no'],
--
reqs['transaction_no'], pay_type, reqs['total_amount'] * 100,
--
reqs['time_start'], "0", reqs['currency'], rate)
--
zx_base:log("ASYNC_SQL", ins_sql)
--
return ins_sql
--
end
--
local function async_db(ins_sql)
--
local db, err = mysql:new()
--
if not db then
--
zx_base:log("ASYNC_DB", "failed to instantiate mysql: ", err)
--
return false
--
end
--
db:set_timeout(1000) -- 1 sec
--
local db_st = zx_base:db_read()
--
local ok, err, errcode, sqlstate = db:connect{
-- host = zx_base:_get_addr(db_st['host'])
,
--
port = db_st['port'],
--
database = db_st['database'],
--
user = db_st['user'],
--
password = db_st['password'],
--
timeout = db_st['timeout'],
--
charset = 'utf8'
--
}
--
if not ok then
--
zx_base:log("ASYNC_DB", err, ": ", errcode, " ", sqlstate)
--
return
--
end
--
local res, err, errcode, sqlstate = db:query(ins_sql)
--
if not res then
--
zx_base:log("ASYNC_DB", "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
--
return
--
end
--
db:set_keepalive(10000, 100)
--
end
local
function
eof
()
if
ngx
.
var
.
host
==
"icm-test.suixingpay.com"
then
ngx
.
log
(
ngx
.
NOTICE
,
ngx
.
req
.
raw_header
())
ngx
.
log
(
ngx
.
NOTICE
,
ngx
.
var
.
http_refer
)
-- if ngx.var.hostname == "icm-test.suixingpay.com" then
if
ngx
.
var
.
remote_addr
==
"106.37.197.50"
then
ngx
.
say
(
"{\"
code
\
":\"
success
\
", \"
msg
\
":\"
成功\
"}"
)
else
ngx
.
say
(
"SUCCESS"
)
...
...
nginx/lua/luabiz/node_asb.lua
View file @
c5379d91
...
...
@@ -21,7 +21,7 @@ local function asb_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_asbdetail.lua
View file @
c5379d91
...
...
@@ -22,7 +22,7 @@ local function asbdetail_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_card.lua
View file @
c5379d91
...
...
@@ -23,7 +23,7 @@ local function card_sql(db_st, total_time)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
@@ -56,26 +56,27 @@ local function card_sql(db_st, total_time)
return
end
-- INSERT INTO history table
local
sql_insert
=
string.format
(
[[INSERT INTO node_card_his SELECT * FROM node_card ]]
..
[[WHERE DATE(`create_time`) < DATE('%s')]]
,
os.date
(
"%Y%m%d%H%M%S"
,
total_time
-
24
*
60
*
60
))
ngx
.
log
(
ngx
.
NOTICE
,
sql_insert
)
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_insert
)
if
not
res
then
ngx
.
log
(
ngx
.
ERR
,
"bad result: "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
end
-- DELETE current tables record
local
sql_delete
=
string.format
(
[[DELETE FROM node_card WHERE DATE(`create_time`) < DATE('%s')]]
,
os.date
(
"%Y%m%d%H%M%S"
,
total_time
-
24
*
60
*
60
))
ngx
.
log
(
ngx
.
NOTICE
,
sql_delete
)
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_delete
)
if
not
res
then
ngx
.
log
(
ngx
.
ERR
,
"bad result: "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
end
-- -- INSERT INTO history table
-- local sql_insert = string.format([[INSERT INTO node_card_his SELECT * FROM node_card ]]..
-- -- [[WHERE DATE(`create_time`) < DATE('%s')]],
-- -- [[WHERE EXTRACT(YEAR_MONTH FROM `create_time`) = EXTRACT(YEAR_MONTH FROM DATE_SUB('%s', INTERVAL 3 MONTH))]],
-- os.date("%Y%m%d%H%M%S", total_time))
-- ngx.log(ngx.NOTICE, sql_insert)
-- local res, err, errcode, sqlstate = db:query(sql_insert)
-- if not res then
-- ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
-- return
-- end
-- -- DELETE current tables record
-- local sql_delete = string.format([[DELETE FROM node_card WHERE DATE(`create_time`) < DATE('%s')]],
-- os.date("%Y%m%d%H%M%S", total_time - 24 * 60 * 60 ))
-- ngx.log(ngx.NOTICE, sql_delete)
-- local res, err, errcode, sqlstate = db:query(sql_delete)
-- if not res then
-- ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
-- return
-- end
ngx
.
log
(
ngx
.
NOTICE
,
"-----------------------> END"
)
zx_base
:
close_db
(
db
)
...
...
nginx/lua/luabiz/node_chgrule.lua
View file @
c5379d91
...
...
@@ -24,7 +24,7 @@ local function chgrule_sql(db_st)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_cs.lua
View file @
c5379d91
...
...
@@ -23,7 +23,7 @@ local function cs_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_csdetail.lua
View file @
c5379d91
...
...
@@ -24,7 +24,7 @@ local function csdetail_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_ms.lua
View file @
c5379d91
...
...
@@ -22,7 +22,7 @@ local function ms_sql(db_st)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_payment.lua
View file @
c5379d91
...
...
@@ -24,7 +24,7 @@ local function payment_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_psb.lua
View file @
c5379d91
...
...
@@ -23,7 +23,7 @@ local function psb_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_psbdetail.lua
View file @
c5379d91
...
...
@@ -23,7 +23,7 @@ local function psbdetail_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_rchg.lua
View file @
c5379d91
...
...
@@ -23,7 +23,7 @@ local function rchg_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_rchgdetail.lua
View file @
c5379d91
...
...
@@ -23,7 +23,7 @@ local function rchgdetail_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_saledetail.lua
View file @
c5379d91
...
...
@@ -24,7 +24,7 @@ local function saledetail_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_saleorder.lua
View file @
c5379d91
...
...
@@ -22,7 +22,7 @@ local function saleorder_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_shift.lua
View file @
c5379d91
...
...
@@ -24,7 +24,7 @@ local function shift_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_sku.lua
View file @
c5379d91
...
...
@@ -24,7 +24,7 @@ local function sku_sql(db_st)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_sms.lua
View file @
c5379d91
...
...
@@ -24,7 +24,7 @@ local function sms_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_smsvip.lua
View file @
c5379d91
...
...
@@ -24,7 +24,7 @@ local function smsvip_sql(db_st, interval)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/node_ticket.lua
View file @
c5379d91
...
...
@@ -20,7 +20,7 @@ local function ticket_sql(db_st, total_time)
db
:
set_timeout
(
1000
)
-- 1 sec
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
@@ -44,28 +44,27 @@ local function ticket_sql(db_st, total_time)
return
end
-- INSERT INTO history table
local
sql_insert
=
string.format
(
[[INSERT INTO node_ticket_his SELECT * FROM node_ticket WHERE ]]
..
[[DATE(`create_time`) < DATE('%s')]]
,
os.date
(
"%Y%m%d%H%M%S"
,
total_time
-
24
*
60
*
60
))
ngx
.
log
(
ngx
.
NOTICE
,
sql_insert
)
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_insert
)
if
not
res
then
ngx
.
log
(
ngx
.
ERR
,
"bad result: "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
end
-- DELETE current tables record
local
sql_delete
=
string.format
(
[[DELETE FROM node_ticket WHERE DATE(`create_time`) < DATE('%s')]]
,
os.date
(
"%Y%m%d%H%M%S"
,
total_time
-
24
*
60
*
60
))
ngx
.
log
(
ngx
.
NOTICE
,
sql_delete
)
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_delete
)
if
not
res
then
ngx
.
log
(
ngx
.
ERR
,
"bad result: "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
end
ngx
.
log
(
ngx
.
NOTICE
,
"-----------------------> END"
)
-- -- INSERT INTO history table
-- local sql_insert = string.format([[INSERT INTO node_ticket_his SELECT * FROM node_ticket WHERE ]]..
-- [[DATE(`create_time`) < DATE('%s')]],
-- os.date("%Y%m%d%H%M%S", total_time - 24 * 60 * 60))
-- ngx.log(ngx.NOTICE, sql_insert)
-- local res, err, errcode, sqlstate = db:query(sql_insert)
-- if not res then
-- ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
-- return
-- end
-- -- DELETE current tables record
-- local sql_delete = string.format([[DELETE FROM node_ticket WHERE DATE(`create_time`) < DATE('%s')]],
-- os.date("%Y%m%d%H%M%S", total_time - 24 * 60 * 60))
-- ngx.log(ngx.NOTICE, sql_delete)
-- local res, err, errcode, sqlstate = db:query(sql_delete)
-- if not res then
-- ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
-- return
-- end
-- ngx.log(ngx.NOTICE, "-----------------------> END")
zx_base
:
close_db
(
db
)
end
...
...
nginx/lua/luabiz/node_vipacct.lua
View file @
c5379d91
...
...
@@ -37,7 +37,7 @@ local function vipacct_sql(db_st)
-- 连接分节点
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
db_st
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
db_st
[
'host'
])
,
port
=
db_st
[
'port'
],
database
=
db_st
[
'database'
],
user
=
db_st
[
'user'
],
...
...
nginx/lua/luabiz/settle.lua
View file @
c5379d91
...
...
@@ -34,14 +34,9 @@ local nxt_time = zx_base:date2time(os.date("%Y-%m-%d 00:30:00", os.time()+24*60*
local
now_time
=
os.time
();
local
delay
=
nxt_time
-
now_time
;
-- local settledate = os.date('%Y-%m-%d', os.time())
-- local now_time = zx_base:date2time(settledate)
local
handler
handler
=
function
(
premature
,
now_tim
e
)
local
function
handler
(
prematur
e
)
if
not
premature
then
-- if nowtime == now_time then
-- settle features start
-- node_asb: run()
...
...
@@ -74,18 +69,7 @@ handler = function(premature, now_time)
handle
:
close
()
end
-- -- reset now_time
-- now_time = tostring(tonumber(now_time) - 1)
-- reset settle time
-- settledate = os.date('%Y-%m-%d', os.time())
-- now_time = zx_base:date2time(settledate)
-- end
nxt_time
=
zx_base
:
date2time
(
os.date
(
"%Y-%m-%d 00:30:00"
,
os.time
()
+
24
*
60
*
60
))
now_time
=
os.time
();
delay
=
nxt_time
-
now_time
;
local
ok
,
err
=
ngx
.
timer
.
every
(
24
*
60
*
60
,
handler
,
now_time
)
local
ok
,
err
=
ngx
.
timer
.
every
(
24
*
60
*
60
,
handler
,
os.time
())
if
not
ok
then
ngx
.
log
(
ngx
.
ERR
,
"failed to create the timer:"
,
err
)
return
...
...
@@ -94,7 +78,7 @@ handler = function(premature, now_time)
end
if
ngx
.
worker
.
id
()
==
0
then
local
ok
,
err
=
ngx
.
timer
.
at
(
delay
,
handler
,
now_time
)
local
ok
,
err
=
ngx
.
timer
.
at
(
delay
,
handler
)
if
not
ok
then
ngx
.
log
(
ngx
.
ERR
,
"failed to create the timer:"
,
err
)
return
...
...
nginx/lua/luabiz/tk_sdt.lua
View file @
c5379d91
...
...
@@ -31,7 +31,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
-- 连接tk_biz
local
ok
,
err
,
errcode
,
sqlstate
=
db_biz
:
connect
{
host
=
tk_biz
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
tk_biz
[
'host'
])
,
port
=
tk_biz
[
'port'
],
database
=
tk_biz
[
'database'
],
user
=
tk_biz
[
'user'
],
...
...
@@ -56,7 +56,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
-- 连接tk_control
local
ok
,
err
,
errcode
,
sqlstate
=
db_control
:
connect
{
host
=
tk_control
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
tk_control
[
'host'
])
,
port
=
tk_control
[
'port'
],
database
=
tk_control
[
'database'
],
user
=
tk_control
[
'user'
],
...
...
nginx/lua/luabiz/tk_sync.lua
View file @
c5379d91
...
...
@@ -34,7 +34,7 @@ local function sync_sql(tk_biz, tk_control, tk_table)
db
:
set_timeout
(
1000
)
-- 1 sec
-- 连接节点机MySQL
local
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
tk_biz
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
tk_biz
[
'host'
])
,
port
=
tk_biz
[
'port'
],
database
=
tk_biz
[
'database'
],
user
=
tk_biz
[
'user'
],
...
...
@@ -76,7 +76,7 @@ local function sync_sql(tk_biz, tk_control, tk_table)
db
:
set_timeout
(
1000
)
-- 连接总控机MySQL
ok
,
err
,
errcode
,
sqlstate
=
db
:
connect
{
host
=
tk_control
[
'host'
]
,
host
=
zx_base
:
_get_addr
(
tk_control
[
'host'
])
,
port
=
tk_control
[
'port'
],
database
=
tk_control
[
'database'
],
user
=
tk_control
[
'user'
],
...
...
nginx/lua/luabiz/zx_base.lua
View file @
c5379d91
...
...
@@ -75,7 +75,7 @@ end
function
ZX_BASE
.
date2time
(
self
,
date
)
-- function date2time(date)
-- function date2time(date)
local
time
local
regex
local
y
,
m
,
d
,
H
,
M
,
S
...
...
@@ -97,4 +97,57 @@ function ZX_BASE.date2time(self, date)
return
time
end
local
require
=
require
local
ngx_re_find
=
ngx
.
re
.
find
local
lrucache
=
require
"resty.lrucache"
local
resolver
=
require
"resty.dns.resolver"
local
cache_storage
=
lrucache
.
new
(
200
)
local
function
_is_addr
(
hostname
)
return
ngx_re_find
(
hostname
,
[[\d+?\.\d+?\.\d+?\.\d+$]]
,
"jo"
)
end
function
ZX_BASE
.
_get_addr
(
self
,
hostname
)
_read_dns_servers_from_resolv_file
()
if
_is_addr
(
hostname
)
then
return
hostname
,
hostname
end
local
addr
=
cache_storage
:
get
(
hostname
)
if
addr
then
return
addr
,
hostname
end
local
r
,
err
=
resolver
:
new
({
nameservers
=
_G
.
_dns_servers
,
retrans
=
5
,
-- 5 retransmissions on receive timeout
timeout
=
2000
,
-- 2 sec
})
if
not
r
then
return
nil
,
hostname
end
local
answers
,
err
=
r
:
query
(
hostname
,
{
qtype
=
r
.
TYPE_A
})
if
not
answers
or
answers
.
errcode
then
return
nil
,
hostname
end
for
i
,
ans
in
ipairs
(
answers
)
do
if
ans
.
address
then
cache_storage
:
set
(
hostname
,
ans
.
address
,
300
)
return
ans
.
address
,
hostname
end
end
return
nil
,
hostname
end
return
ZX_BASE
nginx/lua/luainit/init.lua
View file @
c5379d91
...
...
@@ -45,6 +45,45 @@ function _G.loadmod(namespace)
error
(
module
,
2
)
end
local
pcall
=
pcall
local
io_open
=
io.open
local
ngx_re_gmatch
=
ngx
.
re
.
gmatch
local
json
=
require
(
"cjson"
)
local
ok
,
new_tab
=
pcall
(
require
,
"table.new"
)
if
not
ok
then
new_tab
=
function
(
narr
,
nrec
)
return
{}
end
end
_G
.
_dns_servers
=
new_tab
(
5
,
0
)
local
function
_read_file_data
(
path
)
local
f
,
err
=
io_open
(
path
,
'r'
)
if
not
f
or
err
then
return
nil
,
err
end
local
data
=
f
:
read
(
'*all'
)
f
:
close
()
return
data
,
nil
end
function
_G
.
_read_dns_servers_from_resolv_file
(
self
)
local
text
=
_read_file_data
(
'/etc/resolv.conf'
)
local
captures
,
it
,
err
it
,
err
=
ngx_re_gmatch
(
text
,
[[^nameserver\s+(\d+?\.\d+?\.\d+?\.\d+$)]]
,
"jomi"
)
for
captures
,
err
in
it
do
if
not
err
then
_G
.
_dns_servers
[
#
_G
.
_dns_servers
+
1
]
=
captures
[
1
]
end
end
end
-- _G.fpath = string.format("/var/log/www/S_%s.log", os.date("%Y%m%d"))
-- _G.f = io.open(_G.fpath, "a+")
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment