From 97d74bfa1d4a946e8002042eb2c20032353dc1e7 Mon Sep 17 00:00:00 2001 From: Hossein Shafagh Date: Fri, 12 Jul 2019 08:47:39 -0700 Subject: [PATCH] fixing the app context issue. we will create an app if no current_app available --- lemur/common/celery.py | 5 ++--- lemur/common/redis.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lemur/common/celery.py b/lemur/common/celery.py index b775396a..05e66926 100644 --- a/lemur/common/celery.py +++ b/lemur/common/celery.py @@ -32,9 +32,8 @@ if current_app: else: flask_app = create_app() -red = RedisHandler(host=current_app.config.get('REDIS_HOST', 'localhost'), - port=current_app.config.get('REDIS_PORT', 6379), - db=current_app.config.get('REDIS_DB', 0)).redis() +red = RedisHandler().redis() + def make_celery(app): celery = Celery( diff --git a/lemur/common/redis.py b/lemur/common/redis.py index a996ad67..4af39aef 100644 --- a/lemur/common/redis.py +++ b/lemur/common/redis.py @@ -3,14 +3,18 @@ Helper Class for Redis """ import redis -#from flask import current_app +from flask import current_app +from lemur.factory import create_app +if current_app: + flask_app = current_app +else: + flask_app = create_app() class RedisHandler: - #def __init__(self, host=current_app.config.get('REDIS_HOST', 'localhost'), - # port=current_app.config.get('REDIS_PORT', 6379), - # db=current_app.config.get('REDIS_DB', 0)): - def __init__(self, host, port, db): + def __init__(self, host=flask_app.config.get('REDIS_HOST', 'localhost'), + port=flask_app.config.get('REDIS_PORT', 6379), + db=flask_app.config.get('REDIS_DB', 0)): self.host = host self.port = port self.db = db