This commit is contained in:
parent
a35c1accd6
commit
f277cc7169
24
src/app.py
24
src/app.py
@ -49,28 +49,17 @@ app.config['MQTT_USERNAME'] = MQTT_USERNAME
|
|||||||
app.config['MQTT_PASSWORD'] = MQTT_PASSWORD
|
app.config['MQTT_PASSWORD'] = MQTT_PASSWORD
|
||||||
app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds
|
app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = \
|
app.config['SQLALCHEMY_DATABASE_URI'] = \
|
||||||
f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}"
|
f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}?sslmode=require"
|
||||||
|
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
ma.init_app(app)
|
ma.init_app(app)
|
||||||
mqtt.init_app(app)
|
mqtt.init_app(app)
|
||||||
health = HealthCheck(app, "/healthz")
|
health = HealthCheck()
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
formatter = logging.Formatter(
|
|
||||||
fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s"
|
|
||||||
)
|
|
||||||
|
|
||||||
handler = logging.StreamHandler()
|
|
||||||
handler.setFormatter(formatter)
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
logger.addHandler(handler)
|
|
||||||
|
|
||||||
|
|
||||||
@mqtt.on_log()
|
@mqtt.on_log()
|
||||||
def handle_logging(client, userdata, level, buf):
|
def handle_logging(client, userdata, level, buf):
|
||||||
@ -102,11 +91,4 @@ api.add_resource(SensorOfflineResource, "/devices/{deviceid}/{sensorid}/offline"
|
|||||||
api.add_resource(SensorOnlineResource, "/devices/{deviceid}/{sensorid}/online")
|
api.add_resource(SensorOnlineResource, "/devices/{deviceid}/{sensorid}/online")
|
||||||
|
|
||||||
health.add_check(health_database_status)
|
health.add_check(health_database_status)
|
||||||
|
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
|
||||||
if __name__ == "__main__":
|
|
||||||
app.run(
|
|
||||||
debug=bool(DEBUG),
|
|
||||||
host="0.0.0.0",
|
|
||||||
use_reloader=False,
|
|
||||||
port=int(PORT),
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user