Skip to content

Commit

Permalink
Possible fixed cleanup of processes
Browse files Browse the repository at this point in the history
  • Loading branch information
fall-byrd committed Oct 13, 2024
1 parent 5871d4d commit 2d8a461
Show file tree
Hide file tree
Showing 10 changed files with 595 additions and 426 deletions.
24 changes: 20 additions & 4 deletions backend/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@

from flask import Flask
from flask_cors import CORS
import config

app = Flask(__name__)
CORS(app)
from typing import Callable, Optional

from api import routes

class FlaskApp:

_flask_app = None

def get_flask_app(self) -> Flask:
if self._flask_app is None:
self._flask_app = Flask(__name__)
CORS(self._flask_app)

return self._flask_app

def add_api_route(self, rule: str, endpoint_function: Callable, methods: Optional[list[str]] = None):
flask_app = self.get_flask_app()

if methods:
flask_app.add_url_rule(rule, view_func=endpoint_function, methods=methods)
else:
flask_app.add_url_rule(rule, view_func=endpoint_function)
21 changes: 15 additions & 6 deletions backend/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@
"""
import logging

import api.routes
from api.server import APIServer
from api.routes import RouteManager
from api.server import WaitressAPIServer
# from config import microlabConfig as config
from api.app import app
from api.app import FlaskApp
from microlab.interface import MicrolabInterface


def runFlask(in_queue, out_queue):
def run_flask(in_queue, out_queue):

logging.info("### STARTING API ###")
werkzeugLogger = logging.getLogger("werkzeug")
# suppresses logging of individual requests to endpoints. Prevents log spam
werkzeugLogger.setLevel(logging.WARNING)

api.routes.microlabInterface = MicrolabInterface(in_queue, out_queue)
APIServer(app).run()
microlab_interface = MicrolabInterface(in_queue, out_queue)

flask_app = FlaskApp()

# This handles the routes and registering them to the flask_app instance
RouteManager(flask_app, microlab_interface)

WaitressAPIServer(flask_app.get_flask_app(), microlab_interface).run()

# api.routes.microlabInterface = MicrolabInterface(in_queue, out_queue)
# WaitressAPIServer(get_flask_app()).run()
Loading

0 comments on commit 2d8a461

Please sign in to comment.