mirror of
https://github.com/veops/cmdb.git
synced 2025-08-08 09:53:43 +08:00
fix outside of application context
This commit is contained in:
@@ -11,6 +11,7 @@ from flask import abort
|
||||
from sqlalchemy import or_
|
||||
|
||||
from extensions import db
|
||||
from extensions import rd
|
||||
from models.ci import CI
|
||||
from models.ci_relation import CIRelation
|
||||
from models.ci_type import CITypeAttribute
|
||||
@@ -28,7 +29,6 @@ from lib.query_sql import QUERY_HOSTS_NUM_BY_BU
|
||||
from lib.query_sql import QUERY_HOSTS_NUM_BY_PROJECT
|
||||
from lib.query_sql import QUERY_CIS_BY_IDS
|
||||
from lib.query_sql import QUERY_CIS_BY_VALUE_TABLE
|
||||
from lib.utils import rd
|
||||
from tasks.cmdb import ci_cache
|
||||
from tasks.cmdb import ci_delete
|
||||
|
||||
|
21
lib/utils.py
21
lib/utils.py
@@ -7,8 +7,12 @@ from flask import current_app
|
||||
|
||||
|
||||
class RedisHandler(object):
|
||||
def __init__(self):
|
||||
config = current_app.config
|
||||
def __init__(self, flask_app=None):
|
||||
self.flask_app = flask_app
|
||||
|
||||
def init_app(self, app):
|
||||
self.flask_app = app
|
||||
config = self.flask_app.config
|
||||
try:
|
||||
pool = redis.ConnectionPool(
|
||||
max_connections=config.get("REDIS_MAX_CONN"),
|
||||
@@ -17,14 +21,13 @@ class RedisHandler(object):
|
||||
db=config.get("REDIS_DB"))
|
||||
self.r = redis.Redis(connection_pool=pool)
|
||||
except Exception as e:
|
||||
print e
|
||||
current_app.logger.error("init redis connection failed")
|
||||
|
||||
@classmethod
|
||||
def instance(cls):
|
||||
if not hasattr(cls, "_instance"):
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
# @classmethod
|
||||
# def instance(cls):
|
||||
# if not hasattr(cls, "_instance"):
|
||||
# cls._instance = cls()
|
||||
# return cls._instance
|
||||
|
||||
def get(self, ci_ids, key="CMDB_CI"):
|
||||
try:
|
||||
@@ -51,8 +54,6 @@ class RedisHandler(object):
|
||||
except Exception as e:
|
||||
current_app.logger.error("delete redis key error, %s" % str(e))
|
||||
|
||||
rd = RedisHandler.instance()
|
||||
|
||||
|
||||
def get_page(page):
|
||||
try:
|
||||
|
Reference in New Issue
Block a user