Move log function to async

This commit is contained in:
Mathias DUPEUX 2024-12-30 03:31:25 +01:00
parent 2dc1da3ec2
commit cd023253ea

11
app.py
View file

@ -1,6 +1,7 @@
from flask import Flask, render_template, request from flask import Flask, render_template, request
from datetime import timedelta from datetime import timedelta
from dotenv import load_dotenv from dotenv import load_dotenv
from threading import Thread
from os import getenv from os import getenv
import monitoring import monitoring
import html import html
@ -86,11 +87,11 @@ def home():
if delta > 6: delta = 6 if delta > 6: delta = 6
if delta < 0: delta = 0 if delta < 0: delta = 0
monitoring.log( Thread(target=monitoring.log, kwargs={
ip=request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr), 'ip': request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr),
useragent=request.headers.get('User-Agent'), 'useragent': request.headers.get('User-Agent'),
day=delta 'day': delta
) }).start()
dates = [] dates = []