Commit 075082e14722302f91e33ae99c782b35332101f8
1 parent
6864d374
Exists in
dev
added start of agents (for demo without celery)
Showing
3 changed files
with
50 additions
and
23 deletions
Show diff stats
pyros.py
... | ... | @@ -663,7 +663,7 @@ class Pyros(AManager): |
663 | 663 | self.replacePatternInFile("CELERY_TEST = False", "CELERY_TEST = True", "pyros/settings.py") |
664 | 664 | self.replacePatternInFile("SIMULATOR = False", "SIMULATOR = True", "pyros/settings.py") |
665 | 665 | |
666 | - # Reset the database (Empty the database from any data) | |
666 | + # 0) Reset the database (Empty the database from any data) | |
667 | 667 | #TODO: je crois qu'on n'utilise plus sqlite... donc ce code est inutile ? |
668 | 668 | if self.system == "Windows" : self.execProcess("del /f testdb.sqlite3") |
669 | 669 | else : self.execProcess("rm -f testdb.sqlite3") |
... | ... | @@ -671,10 +671,8 @@ class Pyros(AManager): |
671 | 671 | if TOTAL: self.reset_database_sim() |
672 | 672 | # EP added: |
673 | 673 | if not TOTAL: self.reset_database_sim() |
674 | - | |
675 | 674 | # Actualise l’état de la DB en accord avec l’ensemble des modèles et des migrations actuels |
676 | 675 | self.migrate() |
677 | - | |
678 | 676 | # Load fixture initial_fixture.json |
679 | 677 | self.loaddata() |
680 | 678 | |
... | ... | @@ -683,6 +681,7 @@ class Pyros(AManager): |
683 | 681 | # |
684 | 682 | self.server() |
685 | 683 | self.sleep(2) |
684 | + | |
686 | 685 | self.printFullTerm(Colors.WARNING, "SUMMARY") |
687 | 686 | self.printColor(Colors.GREEN, "The simulator has been successfully initialised") |
688 | 687 | #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): |
695 | 694 | self.printFullTerm(Colors.WARNING, "SUMMARY") |
696 | 695 | |
697 | 696 | # |
698 | - # 2) (if not USE_CELERY) Start Agents | |
699 | - # | |
700 | - if TOTAL and not USE_CELERY : | |
701 | - # Start Environment Monitoring Agent | |
702 | - # Start Majordome Agent | |
703 | - # Start Alert Manager Agent | |
704 | - self.start_agents() | |
705 | - # Needed ? | |
706 | - self.sleep(3) | |
707 | - # | |
708 | 697 | # 2) (if USE_CELERY) Start Celery workers |
709 | 698 | # |
710 | 699 | if USE_CELERY: |
... | ... | @@ -748,6 +737,20 @@ class Pyros(AManager): |
748 | 737 | self.changeDirectory("..") |
749 | 738 | ''' |
750 | 739 | |
740 | + ''' | |
741 | + # | |
742 | + # 2) (if not USE_CELERY) Start Agents | |
743 | + # | |
744 | + if TOTAL and not USE_CELERY : | |
745 | + #pass | |
746 | + # Start Environment Monitoring Agent | |
747 | + # Start Majordome Agent | |
748 | + # Start Alert Manager Agent | |
749 | + self.start_agents() | |
750 | + # Needed ? | |
751 | + self.sleep(3) | |
752 | + ''' | |
753 | + | |
751 | 754 | # When simulators are finished: |
752 | 755 | #self.kill_simulation() |
753 | 756 | return 0 |
... | ... | @@ -767,9 +770,17 @@ class Pyros(AManager): |
767 | 770 | self.changeDirectory("..") |
768 | 771 | return 0 |
769 | 772 | else: self.execProcessAsync("rm -f testdb.sqlite3") |
773 | + | |
770 | 774 | # Kill web server (processes using TCP port 8000) : |
771 | 775 | #self.execProcessAsync("fuser -k 8000/tcp") |
772 | 776 | self.kill_server() |
777 | + | |
778 | + # (if not using celery) Kill all agents : | |
779 | + if not USE_CELERY: | |
780 | + self.execProcessAsync("ps aux | grep \"start_agent_alert_manager.py\" | awk '{ print $2 }' | xargs kill") | |
781 | + self.execProcessAsync("ps aux | grep \"start_agent_monitoring.py\" | awk '{ print $2 }' | xargs kill") | |
782 | + self.execProcessAsync("ps aux | grep \"start_agent_majordome.py\" | awk '{ print $2 }' | xargs kill") | |
783 | + | |
773 | 784 | # Kill all simulators : |
774 | 785 | self.execProcessAsync("ps aux | grep \" domeSimulator.py\" | awk '{ print $2 }' | xargs kill") |
775 | 786 | self.execProcessAsync("ps aux | grep \" userSimulator.py\" | awk '{ print $2 }' | xargs kill") |
... | ... | @@ -800,43 +811,52 @@ class Pyros(AManager): |
800 | 811 | if not os.path.isfile(conf): |
801 | 812 | self.printColor(Colors.FAIL, "The simulation file " + conf + " does not exist") |
802 | 813 | return 1 |
814 | + # Go back to simulators/ | |
815 | + self.changeDirectory("..") | |
803 | 816 | |
804 | 817 | procs = [] |
805 | 818 | |
806 | 819 | # Launch the User simulator: |
807 | - self.changeDirectory("..") | |
808 | 820 | self.changeDirectory("user") |
809 | 821 | procs.append(self.execProcessFromVenvAsync(self.venv_bin + " userSimulator.py " + conf)) |
822 | + self.changeDirectory("..") | |
810 | 823 | |
811 | 824 | # (if TOTAL) Launch all other simulators |
812 | 825 | if TOTAL: |
813 | 826 | |
814 | - self.changeDirectory("..") | |
815 | 827 | self.changeDirectory("dome") |
816 | 828 | procs.append(self.execProcessFromVenvAsync(self.venv_bin + " domeSimulator.py " + conf)) |
817 | - | |
818 | 829 | self.changeDirectory("..") |
830 | + | |
819 | 831 | self.changeDirectory("alert") |
820 | 832 | procs.append(self.execProcessFromVenvAsync(self.venv_bin + " alertSimulator.py " + conf)) |
821 | - | |
822 | 833 | self.changeDirectory("..") |
834 | + | |
823 | 835 | self.changeDirectory("plc") |
824 | 836 | procs.append(self.execProcessFromVenvAsync(self.venv_bin + " plcSimulator.py " + conf)) |
825 | - | |
826 | 837 | self.changeDirectory("..") |
838 | + | |
827 | 839 | self.changeDirectory("camera") |
828 | 840 | procs.append(self.execProcessFromVenvAsync(self.venv_bin + " cameraVISSimulator.py " + conf)) |
829 | 841 | procs.append(self.execProcessFromVenvAsync(self.venv_bin + " cameraNIRSimulator.py " + conf)) |
830 | - | |
831 | 842 | self.changeDirectory("..") |
843 | + | |
832 | 844 | self.changeDirectory("telescope") |
833 | 845 | procs.append(self.execProcessFromVenvAsync(self.venv_bin + " telescopeSimulator.py " + conf)) |
846 | + self.changeDirectory("..") | |
834 | 847 | |
835 | - # Get back to project root folder and wait for end of simulators : | |
836 | - self.changeDirectory("..") | |
848 | + # Get back to project root folder | |
837 | 849 | self.changeDirectory("..") |
850 | + | |
851 | + # (if not celery) Launch agents (env monitor, major, alert mgr) | |
852 | + if not USE_CELERY: | |
853 | + self.start_agents() | |
854 | + | |
855 | + # Wait for end of simulators : | |
838 | 856 | for p in procs: |
839 | 857 | p.wait() |
858 | + | |
859 | + # Kill all processes | |
840 | 860 | self.kill_simulation() |
841 | 861 | return 0 |
842 | 862 | ... | ... |
src/majordome/tasks.py
... | ... | @@ -224,6 +224,8 @@ class Majordome(Task): |
224 | 224 | self.logDB("Timer " + str(timer_name) + " unknown") |
225 | 225 | if (settings.DEBUG and DEBUG_FILE): |
226 | 226 | log.info("Timer : " + str(timer_name) + " executed") |
227 | + # EP added because loop is too quick (without CELERY) | |
228 | + if not settings.USE_CELERY: time.sleep(2) | |
227 | 229 | return (0) |
228 | 230 | |
229 | 231 | ''' | ... | ... |
src/pyros/settings.py
... | ... | @@ -81,7 +81,8 @@ INSTALLED_APPS = [ |
81 | 81 | 'observation_manager', |
82 | 82 | 'routine_manager', |
83 | 83 | 'user_manager', |
84 | - 'devices' | |
84 | + 'devices', | |
85 | + #'kombu.transport.django' | |
85 | 86 | ] |
86 | 87 | |
87 | 88 | MIDDLEWARE_CLASSES = [ |
... | ... | @@ -255,10 +256,14 @@ else: |
255 | 256 | |
256 | 257 | # CELERY CONFIG |
257 | 258 | |
258 | -# CELERY_RESULT_BACKEND = 'rpc://' | |
259 | 259 | CELERY_RESULT_BACKEND = 'amqp' |
260 | +#CELERY_RESULT_BACKEND = 'rpc://' | |
261 | +#CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', | |
262 | + | |
260 | 263 | # (EP) TODO: This should also be added (according to https://simpleisbetterthancomplex.com/tutorial/2017/08/20/how-to-use-celery-with-django.html) |
261 | 264 | #CELERY_BROKER_URL = 'amqp://localhost' |
265 | +#CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672/' | |
266 | +#CELERY_BROKER_URL = 'django://' | |
262 | 267 | |
263 | 268 | CELERY_ACCEPT_CONTENT = ['json'] |
264 | 269 | CELERY_TASK_SERIALIZER = 'json' | ... | ... |