Skip to content

Commit

Permalink
同步代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaobangyu committed Oct 20, 2023
1 parent d035751 commit 2d0b16a
Showing 1 changed file with 86 additions and 15 deletions.
101 changes: 86 additions & 15 deletions server/autotest/client.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
-- 终端
local log_info = logger.info
local log_err = logger.err
local json_encode = json.encode
local log_info = logger.info
local log_err = logger.err
local json_encode = json.encode
local json_decode = json.decode
local tinsert = table.insert

local update_mgr = quanta.get("update_mgr")
local http = quanta.get("http_client")
local update_mgr = quanta.get("update_mgr")
local http = quanta.get("http_client")

local AUTO_TEST_API = environ.get("AUTO_TEST_API")
local BASE_API = environ.get("AUTO_TEST_API")
local USER_LOGIN = "/testtask/user_login"
local USER_HEART = "/testtask/user_heart"
local USER_TASK_LIST = "/testtask/user_task_list"
local TEST_ALLOT = "/testtask/task_allot"
local CASE_INFO = "/testcase/info"

local Client = singleton()
local prop = property(Client)
prop:reader("login", false)
local Client = singleton()
local prop = property(Client)
prop:reader("id", nil)
prop:reader("task_list", nil)

function Client:__init()
log_info("[Client][__init]...")
update_mgr:attach_second5(self)
update_mgr:attach_second30(self)
end

-- 获取主机名称
Expand Down Expand Up @@ -47,31 +56,93 @@ function Client:git_ver()
return git_version or ""
end

-- 请求地址
function Client:request_url(url)
return BASE_API .. url
end

function Client:is_login()
if not self.id or self.id == "" then
return false
end
return true
end

-- 加载验证
function Client:can_load_task()
if not self.task_list then
return true
end
return false
end

-- 分配验证
function Client:can_allot_task()
if not next(self.task_list) then
return true
end
return false
end

function Client:on_second5()
self:update()
end

function Client:on_second30()
-- self:task()
end

-- 账号逻辑
function Client:account()
local host_name = self:host_name()
if not self.login then
if not self:is_login() then
local git_ver = self:git_ver()
local ok, status, res = http:call_post(AUTO_TEST_API .. "/pressclt/login", {}, {},
local ok, status, res = http:call_post(self:request_url(USER_LOGIN), {}, {},
{ host_name = host_name, gitver = git_ver, host_ip = self:host_ip() })
if not ok or status >= 300 then
log_err("[Client][on_second5] login post failed! code: {}, err: {}", status, res)
log_err("[Client][account] login post failed! code: {}, err: {}", status, res)
return
end
self.login = true
log_info("[Client][on_second5] login success,host_name:{} git_ver:{}", host_name, git_ver)
local resdata = json_decode(res)
self.id = resdata.id
log_info("[Client][account] login success,host_name:{} git_ver:{} res:{} id:{}", host_name, git_ver, res, self
.id)
else
http:call_post(AUTO_TEST_API .. "/pressclt/heart", {}, {}, { host_name = host_name })
http:call_post(self:request_url(USER_HEART), {}, {}, { id = self.id })
end
end

-- 任务逻辑
function Client:task()
if not self:is_login() then
return
end

-- 获取任务
if self:can_load_task() then
local ok, status, res = http:call_post(self:request_url(USER_TASK_LIST), {}, {}, { id = self.id })
if not ok or status >= 300 then
log_err("[Client][task] task_list post failed! code: {}, err: {}", status, res)
return
end
local resdata = json_decode(res)
self.task_list = resdata.list or {}
-- 分配任务
elseif self:can_allot_task() then
local ok, status, res = http:call_post(self:request_url(TEST_ALLOT), {}, {}, { id = self.id })
if not ok or status >= 300 then
log_err("[Client][task] task_list post failed! code: {}, err: {}", status, res)
return
end
local resdata = json_decode(res)
for _, task in pairs(resdata.list or {}) do
tinsert(self.task_list, task)
end
else
if next(self.task_list)then

end
end
end

-- 更新定时器
Expand Down

0 comments on commit 2d0b16a

Please sign in to comment.