Conversation
…is then called once at initialisation to create an engine that is used throughout the code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR attmepts to address Issue #108.
There is apparently a limit in the number of concurrent connections that can happen at the same time to a postgreSQL database. When trying to optimise management running instances of wofost in parallel, the whole thing crashes with the following error:
An unexpected error occurred: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: remaining connection slots are reserved for roles with the SUPERUSER attribute.To fix this, I created an utility function that generates a SQLAlchemy engine with a pool_size=300 and max_overflow=100; this is created only once, either when initialising the Uvicorn UkWofost app or when importing anything from ukwofost.core for the first time. This global engine is then used any time a connection to the SQL database is needed. This is clunkier than adding the engine within the app; I had to do this just because the code should also allow to run UkWofost locally and algorithmically without having to start and run the uvicorn server.