mirror of
https://gitee.com/iresty/apisix.git
synced 2024-11-30 02:57:49 +08:00
change: limit the maximum length of Lua code to 100. (#1525)
This commit is contained in:
parent
d970dab5c2
commit
a446cd057b
@ -1,3 +1,4 @@
|
|||||||
std = "ngx_lua"
|
std = "ngx_lua"
|
||||||
unused_args = false
|
unused_args = false
|
||||||
redefined = false
|
redefined = false
|
||||||
|
max_line_length = 100
|
||||||
|
@ -42,8 +42,8 @@ local schema = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local function schedule_func_exec(batch_processor, delay, batch)
|
local function schedule_func_exec(self, delay, batch)
|
||||||
local hdl, err = timer_at(delay, execute_func, batch_processor, batch)
|
local hdl, err = timer_at(delay, execute_func, self, batch)
|
||||||
if not hdl then
|
if not hdl then
|
||||||
core.log.error("failed to create process timer: ", err)
|
core.log.error("failed to create process timer: ", err)
|
||||||
return
|
return
|
||||||
@ -51,55 +51,61 @@ local function schedule_func_exec(batch_processor, delay, batch)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function execute_func(premature, batch_processor, batch)
|
function execute_func(premature, self, batch)
|
||||||
if premature then
|
if premature then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err = batch_processor.func(batch.entries, batch_processor.batch_max_size)
|
local ok, err = self.func(batch.entries, self.batch_max_size)
|
||||||
if not ok then
|
if not ok then
|
||||||
core.log.error("Batch Processor[", batch_processor.name, "] failed to process entries: ", err)
|
core.log.error("Batch Processor[", self.name,
|
||||||
|
"] failed to process entries: ", err)
|
||||||
batch.retry_count = batch.retry_count + 1
|
batch.retry_count = batch.retry_count + 1
|
||||||
if batch.retry_count <= batch_processor.max_retry_count then
|
if batch.retry_count <= self.max_retry_count then
|
||||||
schedule_func_exec(batch_processor, batch_processor.retry_delay, batch)
|
schedule_func_exec(self, self.retry_delay,
|
||||||
|
batch)
|
||||||
else
|
else
|
||||||
core.log.error("Batch Processor[", batch_processor.name,"] exceeded ",
|
core.log.error("Batch Processor[", self.name,"] exceeded ",
|
||||||
"the max_retry_count[", batch.retry_count,"] dropping the entries")
|
"the max_retry_count[", batch.retry_count,
|
||||||
|
"] dropping the entries")
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
core.log.debug("Batch Processor[", batch_processor.name ,"] successfully processed the entries")
|
core.log.debug("Batch Processor[", self.name,
|
||||||
|
"] successfully processed the entries")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function flush_buffer(premature, batch_processor)
|
local function flush_buffer(premature, self)
|
||||||
if premature then
|
if premature then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if now() - batch_processor.last_entry_t >= batch_processor.inactive_timeout or
|
if now() - self.last_entry_t >= self.inactive_timeout or
|
||||||
now() - batch_processor.first_entry_t >= batch_processor.buffer_duration then
|
now() - self.first_entry_t >= self.buffer_duration
|
||||||
core.log.debug("Batch Processor[", batch_processor.name ,"] buffer ",
|
then
|
||||||
|
core.log.debug("Batch Processor[", self.name ,"] buffer ",
|
||||||
"duration exceeded, activating buffer flush")
|
"duration exceeded, activating buffer flush")
|
||||||
batch_processor:process_buffer()
|
self:process_buffer()
|
||||||
batch_processor.is_timer_running = false
|
self.is_timer_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- buffer duration did not exceed or the buffer is active, extending the timer
|
-- buffer duration did not exceed or the buffer is active,
|
||||||
core.log.debug("Batch Processor[", batch_processor.name ,"] extending buffer timer")
|
-- extending the timer
|
||||||
create_buffer_timer(batch_processor)
|
core.log.debug("Batch Processor[", self.name ,"] extending buffer timer")
|
||||||
|
create_buffer_timer(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function create_buffer_timer(batch_processor)
|
function create_buffer_timer(self)
|
||||||
local hdl, err = timer_at(batch_processor.inactive_timeout, flush_buffer, batch_processor)
|
local hdl, err = timer_at(self.inactive_timeout, flush_buffer, self)
|
||||||
if not hdl then
|
if not hdl then
|
||||||
core.log.error("failed to create buffer timer: ", err)
|
core.log.error("failed to create buffer timer: ", err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
batch_processor.is_timer_running = true
|
self.is_timer_running = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -149,7 +155,8 @@ function Batch_Processor:push(entry)
|
|||||||
self.last_entry_t = now()
|
self.last_entry_t = now()
|
||||||
|
|
||||||
if self.batch_max_size <= #entries then
|
if self.batch_max_size <= #entries then
|
||||||
core.log.debug("Batch Processor[", self.name ,"] batch max size has exceeded")
|
core.log.debug("Batch Processor[", self.name ,
|
||||||
|
"] batch max size has exceeded")
|
||||||
self:process_buffer()
|
self:process_buffer()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user