Improve banned forgiveness logic

This commit is contained in:
Piero Toffanin 2021-11-24 12:41:12 -05:00
parent cda2d3ed96
commit 3a7527c418

View file

@ -7,10 +7,19 @@ active = False
threshold = -1 threshold = -1
def clear_banned(): def forgive_banned():
global banned global banned
banned = {}
clear_list = []
for ip in banned:
if banned[ip] <= 0:
clear_list.append(ip)
else:
banned[ip] -= 1
for ip in clear_list:
del banned[ip]
def setup(violations_threshold=100): def setup(violations_threshold=100):
global active global active
@ -20,7 +29,7 @@ def setup(violations_threshold=100):
threshold = violations_threshold threshold = violations_threshold
scheduler = BackgroundScheduler() scheduler = BackgroundScheduler()
scheduler.add_job(func=clear_banned, trigger="interval", weeks=4) scheduler.add_job(func=forgive_banned, trigger="interval", minutes=5)
scheduler.start() scheduler.start()
# Shut down the scheduler when exiting the app # Shut down the scheduler when exiting the app