在nginx.conf中配置

http {
    init_by_lua_file init.lua;
    init_worker_by_lua_file init_worker.lua;
}

init.lua

local process = require "ngx.process"

local ok, err = process.enable_privileged_agent()
if not ok then
    ngx.log(ngx.ERR, "enable privileged agent failed, error: ", err)
end

init_worker.lua

local process = require "ngx.process"

local function timer_work(delay, worker)
    local timer_work

    timer_work = function (premature)
        if not premature then
            local status, msg = pcall( worker )
            if not status then
                ngx_log(ngx_err, "timer work: ", msg)
            end
            ngx_timer_at(delay, timer_work)
        end
    end

    ngx_timer_at(delay, timer_work)
end

local function load_data()

end

if process.type() == "privileged agent" then
    timer_work(delay, load_data)
end

标签: nginx

添加新评论