Did not move to Gunicorn, but now working in Docker
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
### Modules ###
|
||||
###############
|
||||
|
||||
import threading
|
||||
import subprocess
|
||||
import connexion # Imports connexion module
|
||||
from config import CONFIG # Imports the configuration file
|
||||
from manager import * # Imports the Manager file that contains the functions for the API
|
||||
from flask_session import Session # Imports the session module
|
||||
from scheduler import run_schedule # Imports the scheduler module
|
||||
|
||||
|
||||
#################
|
||||
### Connexion ###
|
||||
@@ -20,12 +20,11 @@ def create_app():
|
||||
"""Creates the API using Connexion."""
|
||||
app = connexion.FlaskApp(__name__)
|
||||
app.add_api(CONFIG["server"]["api_file"])
|
||||
|
||||
flask_app = app.app
|
||||
flask_app.config['SECRET_KEY'] = CONFIG["sessions"]["secret_key"]
|
||||
flask_app.config['SESSION_TYPE'] = 'filesystem'
|
||||
|
||||
Session(flask_app)
|
||||
event_logger("Session initialised.")
|
||||
return app
|
||||
|
||||
def API():
|
||||
@@ -33,6 +32,7 @@ def API():
|
||||
app = create_app()
|
||||
debug_value = CONFIG["server"]["debug"]
|
||||
debug = False if debug_value.lower() == 'false' else True
|
||||
event_logger("API started.")
|
||||
app.run(host=CONFIG["server"]["host"], port=CONFIG["server"]["port"], debug=debug)
|
||||
|
||||
################
|
||||
@@ -40,14 +40,12 @@ def API():
|
||||
################
|
||||
|
||||
if __name__ == "__main__":
|
||||
event_logger("Starting API...") # Create a thread that will run the run_schedule function in the background
|
||||
event_logger("Starting API...")
|
||||
scheduler = CONFIG["server"]["scheduler"]
|
||||
scheduler = False if scheduler.lower() == 'false' else True
|
||||
if scheduler:
|
||||
thread = threading.Thread(target=run_schedule)
|
||||
thread.daemon = True # Set the thread as a daemon thread
|
||||
thread.start()
|
||||
subprocess.Popen(["python", "scheduler.py"])
|
||||
event_logger("Scheduler started.")
|
||||
API()
|
||||
event_logger("API stopped.") # This line will only be reached if the API is stopped
|
||||
event_logger("API stopped.")
|
||||
|
||||
Reference in New Issue
Block a user