mirror of
https://github.com/EDCD/EDDN.git
synced 2025-04-25 04:40:53 +03:00
DuplicateMessages: Very initial flake8 pass
This commit is contained in:
parent
e9b4afcdf6
commit
01b5ccf7ac
@ -1,15 +1,20 @@
|
|||||||
# coding: utf8
|
# coding: utf8
|
||||||
|
"""Detect duplicate messages from senders."""
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import re
|
import re
|
||||||
import simplejson
|
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from eddn.conf.Settings import Settings
|
|
||||||
from threading import Lock, Thread
|
from threading import Lock, Thread
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
import simplejson
|
||||||
|
|
||||||
|
from eddn.conf.Settings import Settings
|
||||||
|
|
||||||
|
|
||||||
class DuplicateMessages(Thread):
|
class DuplicateMessages(Thread):
|
||||||
|
"""Class holding all code for duplicate message detection."""
|
||||||
|
|
||||||
max_minutes = Settings.RELAY_DUPLICATE_MAX_MINUTES
|
max_minutes = Settings.RELAY_DUPLICATE_MAX_MINUTES
|
||||||
|
|
||||||
caches = {}
|
caches = {}
|
||||||
@ -21,13 +26,14 @@ class DuplicateMessages(Thread):
|
|||||||
self.daemon = True
|
self.daemon = True
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
"""Expire duplicate messages."""
|
||||||
while True:
|
while True:
|
||||||
sleep(60)
|
sleep(60)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
maxTime = datetime.utcnow()
|
max_time = datetime.utcnow()
|
||||||
|
|
||||||
for key in self.caches.keys():
|
for key in self.caches.keys():
|
||||||
if self.caches[key] + timedelta(minutes=self.max_minutes) < maxTime:
|
if self.caches[key] + timedelta(minutes=self.max_minutes) < max_time:
|
||||||
del self.caches[key]
|
del self.caches[key]
|
||||||
|
|
||||||
def isDuplicated(self, json):
|
def isDuplicated(self, json):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user