Commit 8d9c8345f7c06e7dff84dca5e20cac7ba91cc425
1 parent
fd704a25
Exists in
dev
Renaming commands of AgentSST (Adding prefix 'do') and moving routine work to routine_process_after
Showing
1 changed file
with
8 additions
and
7 deletions
Show diff stats
src/core/pyros_django/agent/AgentSST.py
... | ... | @@ -25,8 +25,8 @@ class AgentSST(Agent): |
25 | 25 | subprocess_dict = {} |
26 | 26 | |
27 | 27 | AGENT_SPECIFIC_COMMANDS = [ |
28 | - "kill_agent", | |
29 | - "restart_agent" | |
28 | + "do_kill_agent", | |
29 | + "do_restart_agent" | |
30 | 30 | ] |
31 | 31 | |
32 | 32 | def __init__(self, name:str=None,sim_computer=None): |
... | ... | @@ -87,6 +87,7 @@ class AgentSST(Agent): |
87 | 87 | cmd = self.VENV_PYTHON +" "+ protocol_folder_abs_path + os.sep + protocol_script_name |
88 | 88 | |
89 | 89 | process = subprocess.Popen(f"{cmd}", shell=True, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) |
90 | + process.poll() | |
90 | 91 | self.subprocess_dict[agent] = process |
91 | 92 | log.info(f"Start agent {agent} with cmd {cmd}") |
92 | 93 | |
... | ... | @@ -117,15 +118,15 @@ class AgentSST(Agent): |
117 | 118 | self.start_agents(agent_name) |
118 | 119 | |
119 | 120 | |
120 | - def kill_agent(self, *args)->None: | |
121 | + def do_kill_agent(self, *args)->None: | |
121 | 122 | agent = args[0] |
122 | 123 | if agent in self.subprocess_dict.keys(): |
123 | 124 | cmd = self.send_cmd_to(agent,"do_exit") |
124 | 125 | return cmd |
125 | 126 | |
126 | - def restart_agent(self, *args)->None: | |
127 | + def do_restart_agent(self, *args)->None: | |
127 | 128 | agent = args[0] |
128 | - self.kill_agent(agent) | |
129 | + self.do_kill_agent(agent) | |
129 | 130 | self.start_agent(agent) |
130 | 131 | # if agent in self.subprocess_dict.keys(): |
131 | 132 | # cmd.set_result(f"Agent {agent} restarted") |
... | ... | @@ -149,7 +150,7 @@ class AgentSST(Agent): |
149 | 150 | def do_things_before_exit(self,abort_cmd_sender): |
150 | 151 | kill_agent_commands = {} |
151 | 152 | for agent in self.subprocess_dict.keys(): |
152 | - cmd = self.kill_agent(agent) | |
153 | + cmd = self.do_kill_agent(agent) | |
153 | 154 | kill_agent_commands[agent] = cmd |
154 | 155 | # wait 10 seconds in order to agents to exit themselves properly |
155 | 156 | time.sleep(10) |
... | ... | @@ -158,7 +159,7 @@ class AgentSST(Agent): |
158 | 159 | while self.subprocess_dict[agent].poll() is None: |
159 | 160 | time.sleep(0.5) |
160 | 161 | |
161 | - def routine_process_before_body(self): | |
162 | + def routine_process_after(self): | |
162 | 163 | now_time = datetime.now(timezone.utc) |
163 | 164 | last_running_commands = AgentCmd.get_commands_sent_by_agent("AgentSST").filter(state="CMD_RUNNING") |
164 | 165 | ... | ... |