35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import time
|
|
|
|
from redis import Redis
|
|
|
|
from llm_server.logging import create_logger
|
|
from llm_server.workers.inferencer import STREAM_NAME_PREFIX
|
|
|
|
|
|
# NOT NEEDED
|
|
|
|
def cleaner():
|
|
r = Redis(db=8)
|
|
stream_info = {}
|
|
logger = create_logger('cleaner')
|
|
|
|
while True:
|
|
all_streams = r.keys(f'{STREAM_NAME_PREFIX}:*')
|
|
processed_streams = []
|
|
for stream in all_streams:
|
|
stream = stream.decode()
|
|
current_size = r.xlen(stream)
|
|
|
|
# If the stream is new or its size has changed, update the size and time in the dictionary
|
|
if stream not in stream_info or current_size != stream_info[stream]['size']:
|
|
stream_info[stream] = {'size': current_size, 'time': time.time()}
|
|
processed_streams.append(stream)
|
|
else:
|
|
# If the size hasn't changed for 5 minutes, delete the stream
|
|
if time.time() - stream_info[stream]['time'] >= 300:
|
|
r.delete(stream)
|
|
logger.debug(f"Stream '{stream}' deleted due to inactivity.")
|
|
del stream_info[stream]
|
|
|
|
time.sleep(60)
|