2017-09-30 13:42:04 +02:00
|
|
|
from random import choice
|
2017-09-25 01:17:04 +02:00
|
|
|
from threading import RLock
|
|
|
|
|
|
|
|
from singleton import Singleton
|
|
|
|
|
|
|
|
# randomise routes after 600 seconds
|
|
|
|
REASSIGN_INTERVAL = 600
|
|
|
|
FLUFF_TRIGGER_TIMEOUT = 300
|
|
|
|
|
|
|
|
@Singleton
|
|
|
|
class DandelionStems():
|
|
|
|
def __init__(self):
|
|
|
|
self.stem = {}
|
2017-09-30 13:42:04 +02:00
|
|
|
self.source = {}
|
2017-09-25 01:17:04 +02:00
|
|
|
self.timeouts = {}
|
|
|
|
self.lock = RLock()
|
|
|
|
|
2017-09-30 13:42:04 +02:00
|
|
|
def add(self, hashId, source, stems):
|
2017-09-25 01:17:04 +02:00
|
|
|
with self.lock:
|
2017-09-30 13:42:04 +02:00
|
|
|
self.stem[hashId] = choice(stems)
|
|
|
|
self.source[hashId] = source
|
2017-09-25 01:17:04 +02:00
|
|
|
self.timeouts[hashId] = time.time()
|
|
|
|
|
|
|
|
def remove(self, hashId):
|
|
|
|
with self.lock:
|
|
|
|
try:
|
|
|
|
del self.stem[hashId]
|
2017-09-30 13:42:04 +02:00
|
|
|
del self.source[hashId]
|
2017-09-25 01:17:04 +02:00
|
|
|
del self.timeouts[hashId]
|
|
|
|
except KeyError:
|
|
|
|
pass
|