diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-03 00:12:19 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-10 19:01:00 +0300 |
| commit | 3a4cd4935dafe6d445daac3b7d6ced409f99aa23 (patch) | |
| tree | 751e4ca259f7f35556fdfabc78dfacdedbad9ac5 /aggro.py | |
| parent | c13734f56e9b01a61cfb66019a71d46c3dfe6f86 (diff) | |
Add web server
Diffstat (limited to 'aggro.py')
| -rw-r--r-- | aggro.py | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -1,19 +1,28 @@ import json import os -import threading + +# from multiprocessing import Process +from threading import Thread import time from app.AggroConfig import AggroConfig from app.MemoryState import memory_state from app.PluginManager import PluginManager -from app.database import setup_db +from app.database import database_manager +from app.server import run_web_server -def run_plugin_thread(): +def run_plugin_thread(manager: PluginManager, config: AggroConfig): print("Plugin thread starting...") manager.run() print("Plugin thread exiting...") +def run_server_thread(config: AggroConfig): + print("Server thread starting...") + run_web_server(config.server_host, config.server_port) + print("Server thread exiting...") + + if __name__ == "__main__": print("Starting aggro. Press CTRL-C to exit.") @@ -23,21 +32,27 @@ if __name__ == "__main__": aggrofile_content = json.loads(f.read()) aggro_config = AggroConfig( + server_host=aggrofile_content.get("server_host", "localhost"), + server_port=aggrofile_content.get("server_port", 8080), db_path=aggrofile_content.get("db_path", "db.json"), plugins=aggrofile_content["plugins"], graph=aggrofile_content["graph"], ) - setup_db(aggro_config) + database_manager.setup(aggro_config) manager = PluginManager(aggro_config) manager.build_plugin_instances() memory_state.running = True - plugin_thread = threading.Thread(target=run_plugin_thread) + plugin_thread = Thread(target=run_plugin_thread, args=[manager, aggro_config]) plugin_thread.start() + server_thread = Thread(target=run_server_thread, args=[aggro_config]) + server_thread.daemon = True + server_thread.start() + try: while memory_state.running: time.sleep(0.1) @@ -45,4 +60,5 @@ if __name__ == "__main__": memory_state.running = False print("Waiting for threads to exit...") plugin_thread.join() + print("Server thread exiting...") print("Main thread exiting...") |
