diff --git a/script/network/http_client.lua b/script/network/http_client.lua index 4ff538da..eec91c9c 100644 --- a/script/network/http_client.lua +++ b/script/network/http_client.lua @@ -97,6 +97,7 @@ function HttpClient:send_request(url, timeout, querys, headers, method, datas) local fmt_url = self:format_url(url, querys) local request, curl_handle = curlm_mgr.create_request(fmt_url, to) if not request then + log_err("[HttpClient][send_request] failed : %s", curl_handle) log_err("[HttpClient][send_request] failed : {}", curl_handle) return false end @@ -112,15 +113,15 @@ function HttpClient:send_request(url, timeout, querys, headers, method, datas) end local ok, err = request[method](datas or "") if not ok then + log_err("[HttpClient][send_request] curl %s failed: %s!", method, err) log_err("[HttpClient][send_request] curl {} failed: {}!", method, err) return false end - local session_id = thread_mgr:build_session_id() self.contexts[curl_handle] = { request = request, session_id = session_id, - time = os.clock() * 1000 + to, + time = quanta.clock_ms + to, } return thread_mgr:yield(session_id, url, to) end @@ -148,3 +149,4 @@ end quanta.http_client = HttpClient() return HttpClient + diff --git a/tools/config/download.lua b/tools/config/download.lua index dd1ea134..82f34cab 100644 --- a/tools/config/download.lua +++ b/tools/config/download.lua @@ -1,3 +1,4 @@ + import("kernel.lua") import("sandbox.lua") import("basic/basic.lua") @@ -8,48 +9,71 @@ import("kernel/timer_mgr.lua") import("kernel/event_mgr.lua") import("kernel/update_mgr.lua") import("network/http_client.lua") -local ssplit = qstring.split -local lstdfs = require("lstdfs") - -local ldir = lstdfs.dir -local log_debug = logger.debug -local event_mgr = quanta.get("event_mgr") -local thread_mgr = quanta.get("thread_mgr") -local http_client = quanta.get("http_client") +local tinster = table.insert +local sformat = string.format +local ssplit = qstring.split +local log_debug = logger.debug +local lstdfs = require("lstdfs") +local lmkdir = lstdfs.mkdir +local thread_mgr = quanta.get("thread_mgr") +local http_client = quanta.get("http_client") +local server_id = quanta.getenv("QUANTA_SERVER_ID") +local host = quanta.getenv("QUANTA_HOST") or "http://10.96.8.40:18080" quanta.startup(function() - ldir("./conf") thread_mgr:fork(function() local data = { - server_id = 11 + server_id = server_id } - - local ok, status, result = http_client:call_get("http://10.98.8.97:18080/env/render_server", data) + local url = sformat("%s/env/render_server", host) + print("url = ", url) + local ok, status, result = http_client:call_get(url, data) + --print(ok, status, result) local response = json.decode(result) - print(response) - for _, value in pairs(response.data.files) do - local name = value.name - local fs = io.open(string.format("./conf/%s", name), 'w') - if fs then - local contents = { } - if value.include and next(value.include) then - for _, conf in pairs(value.include) do - table.insert(contents, string.format("dofile(%s)\n", conf)) + if type(response) ~= 'table' then + return + end + if response.data.env and response.data.files then + local env = response.data.env + print(lmkdir(sformat("./%s", env))) + for _, value in pairs(response.data.files) do + local name = value.name + local path = sformat("./%s/%s", env, name) + local fs = io.open(path, 'w') + if fs then + local contents = { } + if value.include and next(value.include) then + for _, conf in pairs(value.include) do + tinster(contents, sformat("dofile('%s/%s')\n", env, conf)) + end end - end - for _, val in pairs(value.value) do - local split_desc = ssplit(val.desc, '\n') - for _, text in ipairs(split_desc) do - table.insert(contents, string.format("--%s\n", text)) + for _, val in pairs(value.value) do + if val.desc ~= '' then + local split_desc = ssplit(val.desc, '\n') + for _, text in pairs(split_desc) do + if text ~= '' and text ~= '[[' then + tinster(contents, sformat("--%s\n", text)) + end + end + end + + if not val.enable then + tinster(contents, "--") + end + if string.match(val.value, "^%[%[.-%]%]$") then + tinster(contents, sformat("set_env('%s', %s)\n", val.key, val.value)) + else + tinster(contents, sformat("set_env('%s', '%s')\n", val.key, val.value)) + end end - table.insert(contents, string.format("set_env('%s', '%s')\n", val.key, val.value)) + fs:write(table.concat(contents)) + fs:close() + log_debug("write {} successful", name) end - fs:write(table.concat(contents)) - fs:close() - log_debug("write {} successful", name) end end + quanta.run = nil end) end) \ No newline at end of file