@startuml partition init() { start :super.init(); :get name of agentSST from obsconfig and set this value; :start_agents; :time.sleep(10); :self.delay(3); } partition routine_after { repeat :for agent in self.subprocess_dict.keys(); :get agent_survey of agent; if (agent_survey.status is outdated) then (yes) if (process of agent is running) then (yes) :get last_executed_start_agent_cmd; if (last_executed_start_agent_cmd exists) then (yes) if (last_executed_start_agent_cmd was sent between 25 and 30 seconds ago) then (yes) : self.send_cmd_to(self.name,do_start_agent, agent); else (no) endif else (no) if ( do_start_agent command already sent (is_pending or running)) then (yes) else (no) :send_cmd_to(self.name,"do_start_agent",agent); endif endif else (no) :get last_executed_start_or_restart_agent_cmd; if (last_executed_start_or_restart_agent_cmd exists) then (yes) if (last_executed_start_or_reastart_agent_cmd was sent between 25 and 30 seconds ago) then (yes) : self.send_cmd_to(self.name,do_restart_agent, agent); else (no) endif else (no) if ( do_restart_agent command already sent (is_pending or running)) then (yes) else (no) :send_cmd_to(self.name,"do_restart_agent",agent); endif endif endif endif repeat while (); repeat :for agent in self.subprocess_dict.keys(); :log.info(process status (running or not)); repeat while(); } end partition do_things_before_exit(){ start repeat :for agent in self.subprocess_dict.keys(); :self.do_kill(agent); :reset restart counter for agent; repeat while(); :sleep(10); repeat :agent in self.subprocess_dict.keys(); repeat :sleep(0.5) repeat while(wait for agent process to stop); repeat while(); end } partition do_start_agent(agent){ start :self.start_agents(agent); :update nb_try_restart of agent in db; end } partition self.start_agents(agent){ start if (agent) then (yes) : get agent informations from config; if (agent has a protocol) then (yes) : run protocol in subprocess and add it to self.subprocess_dict; : increase nb_try_restart for this agent; endif else (no) if (agents_listed_for_this_computer != None) then (yes) repeat :for agent in agents_listed_for_this_computer; : get agent informations from config; if (agent has a protocol) then (yes) : run protocol in subprocess and add it to self.subprocess_dict; endif repeat while(); else (no) stop endif endif end } partition do_kill_agent(agent){ start if (agent in self.subprocess_dict.keys()) then (yes) :send_cmd_to(agent,"do_exit"); endif end } partition do_restart_agent(agent){ start :get nb_try_restart for agent; if (nb_try_restart for agent > nb_restart_max for agent) then (yes){ :send mail to operator and stop PyROS; else (no) :self.do_kill_agent(agent); :self.do_start_agent(agent); endif :update nb_try_restart in database; end } partition force_kill_agent(agent){ start if (agent in self.subprocess_dict.keys()) then (yes) :agent_process = get process of agent; :agent_process.kill(); else (no) :return None; endif end } @enduml