From 64e567caaca9c56d2d5f2a1bafe01860927e2c0c Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 5 Aug 2021 21:35:02 +0300 Subject: db: traits: Return unique values when fetching sample data --- gn3/db/traits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gn3/db/traits.py b/gn3/db/traits.py index ae1939a..61bc94d 100644 --- a/gn3/db/traits.py +++ b/gn3/db/traits.py @@ -5,7 +5,7 @@ from typing import Any, Dict, Union def get_trait_csv_sample_data(conn: Any, trait_name: int, phenotype_id: int): """Fetch a trait and return it as a csv string""" - sql = ("SELECT Strain.Id, PublishData.Id, Strain.Name, " + sql = ("SELECT DISTINCT Strain.Id, PublishData.Id, Strain.Name, " "PublishData.value, " "PublishSE.error, NStrain.count FROM " "(PublishData, Strain, PublishXRef, PublishFreeze) " -- cgit v1.2.3 From 33700066452e3c5f341b790f015f85fb976d06be Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 7 Aug 2021 11:17:21 +0200 Subject: Update info on running guix container --- README.md | 18 +++++++++++++++--- guix.scm | 11 +++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c1acba1..108dcdb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Simply load up the environment (for development purposes): guix environment --load=guix.scm ``` -Also, make sure you have the *guix-bioinformatics* channel set up. +Also, make sure you have the [guix-bioinformatics](https://git.genenetwork.org/guix-bioinformatics/guix-bioinformatics) channel set up. ```bash env GUIX_PACKAGE_PATH=~/guix-bioinformatics/ ~/.config/guix/current/bin/guix environment --load=guix.scm @@ -22,9 +22,21 @@ python3 Better run a proper container ``` -env GUIX_PACKAGE_PATH=~/guix-bioinformatics/ ~/.config/guix/current/bin/guix environment -C --network --load=guix.scm +env GUIX_PACKAGE_PATH=~/guix-bioinformatics/ ~/.config/guix/current/bin/guix environment -C --network --load=guix.scm ``` +If you get a Guix error, such as `ice-9/boot-9.scm:1669:16: In procedure raise-exception: +error: python-sqlalchemy-stubs: unbound variable` it typically means an update to guix latest is required (i.e., guix pull): + +``` +guix pull +source ~/.config/guix/current/etc/profile +``` + +and try again. + +See also instructions in [.guix.scm](.guix.scm). + #### Running Tests (assuming you are in a guix container; otherwise use venv!) @@ -71,7 +83,7 @@ virtualenv --python python3 venv ```bash # The --ignore-installed flag forces packages to -# get installed in the venv even if they existed +# get installed in the venv even if they existed # in the global env pip install -r requirements.txt --ignore-installed ``` diff --git a/guix.scm b/guix.scm index efef9c1..c18f329 100644 --- a/guix.scm +++ b/guix.scm @@ -17,6 +17,17 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with genenetwork3. If not, see https://www.gnu.org/licenses/. +;; To use this file to build HEAD of gemma: +;; +;; env GUIX_PACKAGE_PATH=~/guix-bioinformatics/ guix build -f guix.scm +;; +;; After checking out the git repo +;; cd ~ ; git clone https://git.genenetwork.org/guix-bioinformatics/guix-bioinformatics +;; +;; To get a development container (e.g., run in emacs shell). +;; +;; env GUIX_PACKAGE_PATH=~/guix-bioinformatics/ guix environment -C -l guix.scm + (use-modules (srfi srfi-1) (srfi srfi-26) -- cgit v1.2.3 From e0476d51603432f60b6412b65486166deabe9e08 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 7 Aug 2021 12:06:49 +0200 Subject: Add gunicorn support for production --- README.md | 23 ++++++++++++++++++++++- gn3/api/general.py | 3 +++ guix.scm | 3 ++- main.py | 6 ++++-- wsgi.py | 11 +++++++++++ 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 wsgi.py diff --git a/README.md b/README.md index 108dcdb..c3a9848 100644 --- a/README.md +++ b/README.md @@ -61,12 +61,33 @@ mypy . #### Running the flask app -To spin up the server: +To spin up the server on its own (for development): ```bash env FLASK_DEBUG=1 FLASK_APP="main.py" flask run --port=8080 ``` +And test with + +``` +curl localhost:8080/api/version +"1.0" +``` + +To run with gunicorn + +``` +gunicorn --bind 0.0.0.0:8080 wsgi:app +``` + +consider the following options for development `--bind 0.0.0.0:$SERVER_PORT --workers=1 --timeout 180 --reload wsgi`. + +And for the scalable production version run + +``` +gunicorn --bind 0.0.0.0:8080 --workers 8 --keep-alive 6000 --max-requests 10 --max-requests-jitter 5 --timeout 1200 wsgi:app +``` + ##### Using python-pip IMPORTANT NOTE: we do not recommend using pip tools, use Guix instead diff --git a/gn3/api/general.py b/gn3/api/general.py index cebb2e3..86fb7b7 100644 --- a/gn3/api/general.py +++ b/gn3/api/general.py @@ -11,6 +11,9 @@ from gn3.commands import run_cmd general = Blueprint("general", __name__) +@general.route("/version") +def version(): + return jsonify("1.0") @general.route("/metadata/upload/", methods=["POST"], strict_slashes=False) diff --git a/guix.scm b/guix.scm index c18f329..f94fe1a 100644 --- a/guix.scm +++ b/guix.scm @@ -82,8 +82,9 @@ #:recursive? #t #:select? git-file?)) (propagated-inputs `(("coreutils" ,coreutils) - ("gemma-wrapper" ,gemma-wrapper) ("csvdiff" ,go-github-com-aswinkarthik-csvdiff) + ("gemma-wrapper" ,gemma-wrapper) + ("gunicorn" ,gunicorn) ("python" ,python-wrapper) ("python-bcrypt" ,python-bcrypt) ("python-flask" ,python-flask) diff --git a/main.py b/main.py index e3ca41a..a587697 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,8 @@ from gn3.app import create_app - app = create_app() -app.run(host="0.0.0.0") + +if __name__ == '__main__': + print("Starting app...") + app.run() diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..d30bc49 --- /dev/null +++ b/wsgi.py @@ -0,0 +1,11 @@ +# import main + +print("STARTING WSGI APP") + +from gn3.app import create_app + +app = create_app() + +if __name__ == "__main__": + print("Starting wsgi app...") + app.run() -- cgit v1.2.3