From 075082e14722302f91e33ae99c782b35332101f8 Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Wed, 28 Mar 2018 16:38:57 +0200 Subject: [PATCH] added start of agents (for demo without celery) --- pyros.py | 62 +++++++++++++++++++++++++++++++++++++++++--------------------- src/majordome/tasks.py | 2 ++ src/pyros/settings.py | 9 +++++++-- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/pyros.py b/pyros.py index 0230d4e..1187fd0 100755 --- a/pyros.py +++ b/pyros.py @@ -663,7 +663,7 @@ class Pyros(AManager): self.replacePatternInFile("CELERY_TEST = False", "CELERY_TEST = True", "pyros/settings.py") self.replacePatternInFile("SIMULATOR = False", "SIMULATOR = True", "pyros/settings.py") - # Reset the database (Empty the database from any data) + # 0) Reset the database (Empty the database from any data) #TODO: je crois qu'on n'utilise plus sqlite... donc ce code est inutile ? if self.system == "Windows" : self.execProcess("del /f testdb.sqlite3") else : self.execProcess("rm -f testdb.sqlite3") @@ -671,10 +671,8 @@ class Pyros(AManager): if TOTAL: self.reset_database_sim() # EP added: if not TOTAL: self.reset_database_sim() - # Actualise l’état de la DB en accord avec l’ensemble des modèles et des migrations actuels self.migrate() - # Load fixture initial_fixture.json self.loaddata() @@ -683,6 +681,7 @@ class Pyros(AManager): # self.server() self.sleep(2) + self.printFullTerm(Colors.WARNING, "SUMMARY") self.printColor(Colors.GREEN, "The simulator has been successfully initialised") #TODO: (EP) verifier mais je pense que cette info est obsolete, c'est MySQL qui est utilisé, pas sqlite @@ -695,16 +694,6 @@ class Pyros(AManager): self.printFullTerm(Colors.WARNING, "SUMMARY") # - # 2) (if not USE_CELERY) Start Agents - # - if TOTAL and not USE_CELERY : - # Start Environment Monitoring Agent - # Start Majordome Agent - # Start Alert Manager Agent - self.start_agents() - # Needed ? - self.sleep(3) - # # 2) (if USE_CELERY) Start Celery workers # if USE_CELERY: @@ -748,6 +737,20 @@ class Pyros(AManager): self.changeDirectory("..") ''' + ''' + # + # 2) (if not USE_CELERY) Start Agents + # + if TOTAL and not USE_CELERY : + #pass + # Start Environment Monitoring Agent + # Start Majordome Agent + # Start Alert Manager Agent + self.start_agents() + # Needed ? + self.sleep(3) + ''' + # When simulators are finished: #self.kill_simulation() return 0 @@ -767,9 +770,17 @@ class Pyros(AManager): self.changeDirectory("..") return 0 else: self.execProcessAsync("rm -f testdb.sqlite3") + # Kill web server (processes using TCP port 8000) : #self.execProcessAsync("fuser -k 8000/tcp") self.kill_server() + + # (if not using celery) Kill all agents : + if not USE_CELERY: + self.execProcessAsync("ps aux | grep \"start_agent_alert_manager.py\" | awk '{ print $2 }' | xargs kill") + self.execProcessAsync("ps aux | grep \"start_agent_monitoring.py\" | awk '{ print $2 }' | xargs kill") + self.execProcessAsync("ps aux | grep \"start_agent_majordome.py\" | awk '{ print $2 }' | xargs kill") + # Kill all simulators : self.execProcessAsync("ps aux | grep \" domeSimulator.py\" | awk '{ print $2 }' | xargs kill") self.execProcessAsync("ps aux | grep \" userSimulator.py\" | awk '{ print $2 }' | xargs kill") @@ -800,43 +811,52 @@ class Pyros(AManager): if not os.path.isfile(conf): self.printColor(Colors.FAIL, "The simulation file " + conf + " does not exist") return 1 + # Go back to simulators/ + self.changeDirectory("..") procs = [] # Launch the User simulator: - self.changeDirectory("..") self.changeDirectory("user") procs.append(self.execProcessFromVenvAsync(self.venv_bin + " userSimulator.py " + conf)) + self.changeDirectory("..") # (if TOTAL) Launch all other simulators if TOTAL: - self.changeDirectory("..") self.changeDirectory("dome") procs.append(self.execProcessFromVenvAsync(self.venv_bin + " domeSimulator.py " + conf)) - self.changeDirectory("..") + self.changeDirectory("alert") procs.append(self.execProcessFromVenvAsync(self.venv_bin + " alertSimulator.py " + conf)) - self.changeDirectory("..") + self.changeDirectory("plc") procs.append(self.execProcessFromVenvAsync(self.venv_bin + " plcSimulator.py " + conf)) - self.changeDirectory("..") + self.changeDirectory("camera") procs.append(self.execProcessFromVenvAsync(self.venv_bin + " cameraVISSimulator.py " + conf)) procs.append(self.execProcessFromVenvAsync(self.venv_bin + " cameraNIRSimulator.py " + conf)) - self.changeDirectory("..") + self.changeDirectory("telescope") procs.append(self.execProcessFromVenvAsync(self.venv_bin + " telescopeSimulator.py " + conf)) + self.changeDirectory("..") - # Get back to project root folder and wait for end of simulators : - self.changeDirectory("..") + # Get back to project root folder self.changeDirectory("..") + + # (if not celery) Launch agents (env monitor, major, alert mgr) + if not USE_CELERY: + self.start_agents() + + # Wait for end of simulators : for p in procs: p.wait() + + # Kill all processes self.kill_simulation() return 0 diff --git a/src/majordome/tasks.py b/src/majordome/tasks.py index 97e82a9..2ea7df8 100644 --- a/src/majordome/tasks.py +++ b/src/majordome/tasks.py @@ -224,6 +224,8 @@ class Majordome(Task): self.logDB("Timer " + str(timer_name) + " unknown") if (settings.DEBUG and DEBUG_FILE): log.info("Timer : " + str(timer_name) + " executed") + # EP added because loop is too quick (without CELERY) + if not settings.USE_CELERY: time.sleep(2) return (0) ''' diff --git a/src/pyros/settings.py b/src/pyros/settings.py index 163470b..9ee266b 100644 --- a/src/pyros/settings.py +++ b/src/pyros/settings.py @@ -81,7 +81,8 @@ INSTALLED_APPS = [ 'observation_manager', 'routine_manager', 'user_manager', - 'devices' + 'devices', + #'kombu.transport.django' ] MIDDLEWARE_CLASSES = [ @@ -255,10 +256,14 @@ else: # CELERY CONFIG -# CELERY_RESULT_BACKEND = 'rpc://' CELERY_RESULT_BACKEND = 'amqp' +#CELERY_RESULT_BACKEND = 'rpc://' +#CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', + # (EP) TODO: This should also be added (according to https://simpleisbetterthancomplex.com/tutorial/2017/08/20/how-to-use-celery-with-django.html) #CELERY_BROKER_URL = 'amqp://localhost' +#CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672/' +#CELERY_BROKER_URL = 'django://' CELERY_ACCEPT_CONTENT = ['json'] CELERY_TASK_SERIALIZER = 'json' -- libgit2 0.21.2