From b463c95e0f4ea2af9fb78966d010c8fb6e3873f1 Mon Sep 17 00:00:00 2001 From: jrusso1020 Date: Sun, 10 Nov 2019 16:38:20 -0500 Subject: [PATCH] Fix Gunicorn 20 error This fixes two errors, one where we were not importing HTTPerror appopriately in tasks.py which led to the app crashing and a second error introduced by upgrading gunicorn. Gunicorn was upgraded to version 20 from 19.9 which was a major version upgrade and introduced a breaking change. The change is documented by this issue on the git repo https://github.com/benoitc/gunicorn/issues/2159 it is related to removing an eval statement so we can no longer have gunicorn call a function to create our app. We have gone with a solution introduced in this issue, to call the create_app function and then export a variable where this application is saved. We then call this variable in our Procfile where we run our server using Gunicorn. This should fix our issue for now, and if gunicorn fixes the issue in the libarary then we could always revert but I think this should work going forward. --- Procfile | 2 +- app/__init__.py | 2 +- app/app.py | 2 ++ app/tasks.py | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Procfile b/Procfile index 066a0df..dbc0895 100644 --- a/Procfile +++ b/Procfile @@ -1,4 +1,4 @@ -web: pipenv run gunicorn "app:create_app()" --workers 8 --log-file - +web: pipenv run gunicorn "app:bsafe" --workers 8 --log-file - worker: pipenv run flask worker --threads 1 periodiq: pipenv run flask periodiq diff --git a/app/__init__.py b/app/__init__.py index 819ccf0..8db526a 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1 +1 @@ -from .app import create_app +from .app import bsafe diff --git a/app/app.py b/app/app.py index a9412da..1ab32d7 100644 --- a/app/app.py +++ b/app/app.py @@ -38,3 +38,5 @@ def configure_logging(app): logging.FileHandler(f"{app.config['LOG_FOLDER']}/log.log"), logging.StreamHandler() ]) + +bsafe = create_app() diff --git a/app/tasks.py b/app/tasks.py index d56386b..6b570b9 100644 --- a/app/tasks.py +++ b/app/tasks.py @@ -17,6 +17,7 @@ import os import datetime import requests +from urllib.error import HTTPError from periodiq import PeriodiqMiddleware, cron from ergo_analytics import LoadElasticSearch from ergo_analytics import DataFilterPipeline