membphis commented on a change in pull request #2596: URL: https://github.com/apache/apisix/pull/2596#discussion_r518844505
########## File path: apisix/timers.lua ########## @@ -0,0 +1,89 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +local core = require("apisix.core") +local process = require("ngx.process") +local pairs = pairs +local unpack = unpack +local thread_spawn = ngx.thread.spawn +local thread_wait = ngx.thread.wait + + +local timers = {} + + +local _M = {} + + +local function background_timer() + local threads = {} + for name, timer in pairs(timers) do + core.log.info("run timer[", name, "]") + + local th, err = thread_spawn(timer) + if not th then + core.log.error("failed to spawn thread for timer [", name, "]: ", err) + end + + core.table.insert(threads, th) + end + + local ok, err = thread_wait(unpack(threads)) + if not ok then + core.log.error("failed to wait threads: ", err) + end +end + + +local function is_privileged() + return process.type() == "privileged agent" or process.type() == "single" +end + + +function _M.init_worker() + -- currently only log-rotate needs the timer Review comment: only for plugin `log-rotate`, the current way is enough. but I think this library can be used for different plugins, it is basic library. so I think we should remove https://github.com/apache/apisix/pull/2596/files#diff-6ff817ed7efbdfcf2da85cb1a68a48aa2ef9e18422b80b2f255fc41032ee773eR58-R60 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
