Database migration tool, deduplication of sets data, customizable checkboxes #44

Merged
FrederikBaerentsen merged 51 commits from gregoo/BrickTracker:master into master 2025-01-24 19:12:12 +01:00
3 changed files with 34 additions and 18 deletions
Showing only changes of commit a6ab53efa7 - Show all commits

28
app.py
View File

@ -11,6 +11,10 @@ from bricktracker.socket import BrickSocket # noqa: E402
logger = logging.getLogger(__name__)
# Create the app
# Using 'app' globally interferse with the teardown handlers of Flask
def create_app(main: bool = False, /) -> Flask | BrickSocket:
# Create the Flask app
app = Flask(__name__)
@ -23,16 +27,28 @@ s = BrickSocket(
threaded=not app.config['NO_THREADED_SOCKET'],
)
if main:
return s
else:
return app
if __name__ == '__main__':
s = create_app(True)
# This never happens, but makes the linter happy
if isinstance(s, Flask):
logger.critical('Cannot run locally with a Flask object, needs a BrickSocket. Use create_app(True) to return a BrickSocket') # noqa: E501
exit(1)
# Run the application
logger.info('Starting BrickTracker on {host}:{port}'.format(
host=app.config['HOST'],
port=app.config['PORT'],
host=s.app.config['HOST'],
port=s.app.config['PORT'],
))
s.socket.run(
app,
host=app.config['HOST'],
debug=app.config['DEBUG'],
port=app.config['PORT'],
s.app,
host=s.app.config['HOST'],
debug=s.app.config['DEBUG'],
port=s.app.config['PORT'],
)

View File

@ -96,6 +96,6 @@ def setup_app(app: Flask) -> None:
g.version = __version__
# Make sure all connections are closed at the end
@app.teardown_appcontext
def close_connections(exception, /) -> None:
@app.teardown_request
def teardown_request(_: BaseException | None) -> None:
close()

View File

@ -13,4 +13,4 @@ then
fi
# Execute the WSGI server
gunicorn --bind "${BK_SERVER}:${BK_PORT}" "app:app" --worker-class "eventlet" "$@"
gunicorn --bind "${BK_SERVER}:${BK_PORT}" "app:create_app()" --worker-class "eventlet" "$@"