diff --git a/README.md b/README.md index 282453a..892ad5b 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,13 @@ Author: E. Pallier VERSION: 0.20.16 Comment: + Simplification du mode processus (presque aussi simple que thread) + Bugfixes & New test - Bugfix specific_process() en mode "processus" => meilleure gestion accès concurrent à la BD - Bugfix Agent => fonctionne aussi en mode SIMU OFF - Ajout d'un gros test à la fin pour s'assurer que les résultats sont conformes à l'attendu (only en mode simu) + - Rappel : il suffit de mettre la constante RUN_IN_THREAD de AgentX à False ou True -------------------------------------------------------------------------------------------- diff --git a/src/agent/Agent.py b/src/agent/Agent.py index 96b53c0..ac0cd15 100644 --- a/src/agent/Agent.py +++ b/src/agent/Agent.py @@ -24,9 +24,8 @@ from django import db """TODO: - 1 log par agent + lastlog (30 dernières lignes) -- 1 table par agent - table agents_log avec log minimum pour affichage dans dashboard, et ordre chrono intéressant pour suivi activité : nom agent, timestamp, message -- table agent__vars : nom variable, value, desc +- 1 table par agent: agent__vars : nom variable, value, desc """ @@ -537,11 +536,11 @@ class Agent: print("Updating the survey database table...") print("- fetching table line for agent", self.name) # only necessary when using process (not necessary with threads) - with transaction.atomic(): - self._agent_survey = AgentSurvey.objects.get(name=self.name) - self._agent_survey.mode = self.mode - self._agent_survey.status = self.status - self._agent_survey.save() + #with transaction.atomic(): + self._agent_survey = AgentSurvey.objects.get(name=self.name) + self._agent_survey.mode = self.mode + self._agent_survey.status = self.status + self._agent_survey.save() def simulator_send_command_to_myself(self): @@ -743,7 +742,14 @@ class Agent: def specific_process(self, cmd:Command): """ - Sublevel Loop (only if ACTIVE) : + Sublevel Loop (only if ACTIVE) + + Dans le cas du Majordome, le specific_process() doit lancer + la prise d'une séquence. La sequence elle même va être une + boucle dans le specific_process. Donc on peut voir une séquence + comme un appel unique à une fonction qui va durer un certain + temps (max 20 min par exemple) mais dans la méthode + specific_process il y a une boucle sur la prise des images. """ self.set_status(self.STATUS_SPECIFIC_PROCESS) assert self.is_active() @@ -825,11 +831,14 @@ class Agent: multiprocessing.current_process().name, threading.current_thread().name) ) + cmd.set_as_running() + """ if self.RUN_IN_THREAD: cmd.set_as_running() else: with transaction.atomic(): cmd.set_as_running() + """ # Default body of the specific processing # Should be overriden by subclass @@ -841,11 +850,14 @@ class Agent: def thread_exec_specific_cmd_end(self): """ specific command execution tearing down """ cmd = self._current_specific_cmd + cmd.set_as_processed() + """ if self.RUN_IN_THREAD: cmd.set_as_processed() else: with transaction.atomic(): cmd.set_as_processed() + """ print(">>>>> Thread: ended execution of command", cmd.name) cmd = None # No more current thread diff --git a/src/agent/AgentX.py b/src/agent/AgentX.py index 21c046b..1d867c2 100644 --- a/src/agent/AgentX.py +++ b/src/agent/AgentX.py @@ -95,6 +95,8 @@ class AgentX(Agent): def cmd_step1(self, step:int): cmd = self._current_specific_cmd cmd.result = f"in step #{step}/{self._thread_total_steps_number}" + cmd.save() + """ if self.RUN_IN_THREAD: print("(save from thread)") cmd.save() @@ -102,8 +104,10 @@ class AgentX(Agent): #@transaction.atomic print("(save from process)") with transaction.atomic(): - #Command.objects.select_for_update() cmd.save() + #Command.objects.select_for_update() + """ + def cmd_step2(self, step:int): self.cmd_step1(step) def cmd_step3(self, step:int): @@ -131,13 +135,23 @@ class AgentX(Agent): # This is optional self.thread_set_total_steps_number(5) # HERE, write your own scenario - self.thread_exec_specific_cmd_step(1, self.cmd_step1) + + # scenario OK + self.thread_exec_specific_cmd_step(1, self.cmd_step1, 1) self.thread_exec_specific_cmd_step(2, self.cmd_step2, 3) self.thread_exec_specific_cmd_step(3, self.cmd_step1, 5) self.thread_exec_specific_cmd_step(4, self.cmd_step3, 10) self.thread_exec_specific_cmd_step(5, self.cmd_step1, 4) # ... as many as you need + """ autre scenario + self.thread_exec_specific_cmd_step(1, self.cmd_step1, 1) + self.thread_exec_specific_cmd_step(2, self.cmd_step2, 2) + self.thread_exec_specific_cmd_step(3, self.cmd_step1, 2) + self.thread_exec_specific_cmd_step(4, self.cmd_step3, 2) + self.thread_exec_specific_cmd_step(5, self.cmd_step1, 3) + """ + ''' # @override def exec_specific_cmd_end(self, cmd:Command, from_thread=True): -- libgit2 0.21.2