Skip to content

Commit

Permalink
Control exit delay in reset request
Browse files Browse the repository at this point in the history
  • Loading branch information
raulikak committed Apr 30, 2024
1 parent c50b6e0 commit 5a79dd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tcsfw/client_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def api_exit(self, _request: APIRequest, data: bytes) -> Dict:
clear_db = bool(param.get("clear_db", False))
if clear_db:
self.registry.clear_database()
return {}
return param

def api_post_file(self, request: APIRequest, data_file: pathlib.Path) -> Dict:
"""Post API data in ZIP file"""
Expand Down
7 changes: 6 additions & 1 deletion tcsfw/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,18 @@ async def handle_reload(self, request: web.Request):
req = APIRequest.parse(request.path_qs)
data = await request.content.read() if request.content else b""
res = self.api.api_exit(req, data)
exit_delay = int(res.get("exit_delay", 1000))
res = {} # do not return the parameters

# reload means exiting this process, delay it for response to be sent
def do_exit():
# return code 0 for successful exit
sys.exit(0) # pylint: disable=consider-using-sys-exit

self.loop.call_later(1, do_exit)
if exit_delay > 0:
self.loop.call_later(exit_delay / 1000, do_exit)
else:
do_exit() # no response will be sent
return web.Response(text=json.dumps(res))

def dump_model(self, channel: WebsocketChannel):
Expand Down

0 comments on commit 5a79dd1

Please sign in to comment.