diff options
| author | ruki <[email protected]> | 2022-04-06 00:40:33 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-06 00:40:33 +0800 |
| commit | 824d3af986a880887a616fc96e0cfe96433180bd (patch) | |
| tree | 3aa408b5ad5723ca12de367f749565cf19d19815 /xmake/modules | |
| parent | bf226fd5e7de61181a962df2667d356d8b6f3dd5 (diff) | |
impl show status
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/service/client/client.lua | 72 | ||||
| -rw-r--r-- | xmake/modules/private/service/client/remote_build_client.lua | 47 | ||||
| -rw-r--r-- | xmake/modules/private/service/connect_service.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/private/service/disconnect_service.lua | 11 | ||||
| -rw-r--r-- | xmake/modules/private/service/reconnect_service.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/private/service/show_status.lua | 15 |
6 files changed, 156 insertions, 11 deletions
diff --git a/xmake/modules/private/service/client/client.lua b/xmake/modules/private/service/client/client.lua new file mode 100644 index 000000000..037535ad1 --- /dev/null +++ b/xmake/modules/private/service/client/client.lua @@ -0,0 +1,72 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file client.lua +-- + +-- imports +import("core.base.object") +import("core.base.socket") +import("core.base.scheduler") + +-- define module +local client = client or object() + +-- init client +function client:init() +end + +-- get class +function client:class() + return client +end + +-- get working directory +function client:workdir() + return os.tmpfile(tostring(self)) .. ".dir" +end + +-- is connected? +function client:is_connected() + return os.isfile(self:statusfile()) +end + +-- get the status +function client:status() + local status = self._STATUS + local statusfile = self:statusfile() + if not status and os.isfile(statusfile) then + status = io.load(statusfile) + self._STATUS = status + end + return status +end + +-- get the status file +function client:statusfile() + return path.join(self:workdir(), "status.txt") +end + +function client:__tostring() + return "<client>" +end + +function main() + local instance = client() + instance:init() + return instance +end diff --git a/xmake/modules/private/service/client/remote_build_client.lua b/xmake/modules/private/service/client/remote_build_client.lua new file mode 100644 index 000000000..b4e95e45c --- /dev/null +++ b/xmake/modules/private/service/client/remote_build_client.lua @@ -0,0 +1,47 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file remote_build_client.lua +-- + +-- imports +import("private.service.config") +import("private.service.client.client") + +-- define module +local remote_build_client = remote_build_client or client() +local super = remote_build_client:class() + +-- init client +function remote_build_client:init() + super.init(self) +end + +-- get class +function remote_build_client:class() + return remote_build_client +end + +function remote_build_client:__tostring() + return "<remote_build_client>" +end + +function main() + local instance = remote_build_client() + instance:init() + return instance +end diff --git a/xmake/modules/private/service/connect_service.lua b/xmake/modules/private/service/connect_service.lua index fef2231f4..b103e769b 100644 --- a/xmake/modules/private/service/connect_service.lua +++ b/xmake/modules/private/service/connect_service.lua @@ -23,6 +23,7 @@ import("core.base.option") import("core.base.socket") import("core.base.scheduler") import("private.service.config") +import("private.service.client.remote_build_client") function _get_address() local addr, port @@ -39,17 +40,21 @@ function _get_address() return addr, port end -function _session(addr, port) - print("connect %s:%d ..", addr, port) +function _connect(addr, port) + local client = remote_build_client() + local statusfile = client:statusfile() local sock = socket.connect(addr, port) + print("%s: connect %s:%d ..", client, addr, port) if sock then - print("%s: connected!", sock) + print("%s: connected!", client) + io.save(statusfile, {addr = addr, port = port}) else - print("connect %s:%d failed", addr, port) + print("%s: connect %s:%d failed", client, addr, port) + os.tryrm(statusfile) end end function main() - scheduler.co_start(_session, _get_address()) + scheduler.co_start(_connect, _get_address()) end diff --git a/xmake/modules/private/service/disconnect_service.lua b/xmake/modules/private/service/disconnect_service.lua index f39b29068..ac8d16af7 100644 --- a/xmake/modules/private/service/disconnect_service.lua +++ b/xmake/modules/private/service/disconnect_service.lua @@ -20,9 +20,16 @@ -- imports import("core.base.option") -import("private.service.service") +import("core.base.socket") +import("core.base.scheduler") +import("private.service.config") +import("private.service.client.remote_build_client") function main() - -- TODO + local client = remote_build_client() + local statusfile = client:statusfile() + os.tryrm(statusfile) + print("%s: disconnected!", client) end + diff --git a/xmake/modules/private/service/reconnect_service.lua b/xmake/modules/private/service/reconnect_service.lua index 1032a3abe..d41c14953 100644 --- a/xmake/modules/private/service/reconnect_service.lua +++ b/xmake/modules/private/service/reconnect_service.lua @@ -19,10 +19,11 @@ -- -- imports -import("core.base.option") -import("private.service.service") +import("private.service.connect_service") +import("private.service.disconnect_service") function main() - -- TODO + disconnect_service(); + connect_service(); end diff --git a/xmake/modules/private/service/show_status.lua b/xmake/modules/private/service/show_status.lua index 0a61fae7a..1eb1fe7c1 100644 --- a/xmake/modules/private/service/show_status.lua +++ b/xmake/modules/private/service/show_status.lua @@ -20,8 +20,21 @@ -- imports import("core.base.option") -import("private.service.service") +import("core.base.socket") +import("core.base.scheduler") +import("private.service.config") +import("private.service.client.remote_build_client") function main() + local client = remote_build_client() + local status = client:status() + if status then + print("%s: connected", client) + print(status) + else + print("%s: disconnected", client) + end end + + |
