made InfluxDB optional
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2021-07-26 12:51:52 +02:00
parent 3c10a351ba
commit f15517af62
3 changed files with 19 additions and 15 deletions

View File

@ -40,11 +40,13 @@ api = Api(app)
health = HealthCheck() health = HealthCheck()
db.init_app(app) db.init_app(app)
ma.init_app(app) ma.init_app(app)
if Config.ENABLE_INFLUXDB:
influx_db.init_app(app) influx_db.init_app(app)
@app.before_first_request @app.before_first_request
def init_db(): def init_db():
if Config.ENABLE_INFLUXDB:
influx_db.database.create(Config.INFLUXDB_DATABASE) influx_db.database.create(Config.INFLUXDB_DATABASE)
db.create_all() db.create_all()

View File

@ -40,6 +40,7 @@ class Config:
STORAGE_HOSTNAME = os.getenv("INPUT_STORAGE_HOSTNAME", "localhost:8042") STORAGE_HOSTNAME = os.getenv("INPUT_STORAGE_HOSTNAME", "localhost:8042")
ENABLE_INFLUXDB = os.environ.get("INPUT_ENABLE_INFLUX", "true").lower() in ["true", "yes", "1"]
INFLUXDB_HOST = os.getenv("INFLUX_HOST", "input-influx") INFLUXDB_HOST = os.getenv("INFLUX_HOST", "input-influx")
INFLUXDB_PORT = os.getenv("INFLUX_PORT", "8086") INFLUXDB_PORT = os.getenv("INFLUX_PORT", "8086")
INFLUXDB_USER = os.getenv("INFLUX_USERNAME", "input-service") INFLUXDB_USER = os.getenv("INFLUX_USERNAME", "input-service")

View File

@ -118,6 +118,7 @@ class SampleResource(Resource):
current_app.logger.exception(e) current_app.logger.exception(e)
return abort(569, "AMPQ Publish error") return abort(569, "AMPQ Publish error")
if current_app.config['ENABLE_INFLUXDB']:
influx_db.write_points( influx_db.write_points(
[ [
{ {