fix 目录监控控重

This commit is contained in:
jxxghp
2024-12-31 12:42:28 +08:00
parent bb478c949a
commit 4b3f04c73f
2 changed files with 10 additions and 5 deletions
+2 -5
View File
@@ -364,11 +364,8 @@ class TransferChain(ChainBase, metaclass=Singleton):
# 文件整理线程 # 文件整理线程
_transfer_thread = None _transfer_thread = None
# 队列等待时间(秒)
_queue_timeout = 5
# 队列间隔时间(秒) # 队列间隔时间(秒)
_transfer_interval = 10 _transfer_interval = 15
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@@ -536,7 +533,7 @@ class TransferChain(ChainBase, metaclass=Singleton):
while not global_vars.is_system_stopped: while not global_vars.is_system_stopped:
try: try:
item: TransferQueue = self._queue.get(timeout=self._queue_timeout) item: TransferQueue = self._queue.get(block=False)
if item: if item:
task = item.task task = item.task
if not task: if not task:
+8
View File
@@ -6,6 +6,7 @@ from threading import Lock
from typing import Any from typing import Any
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from cachetools import TTLCache
from watchdog.events import FileSystemEventHandler, FileSystemMovedEvent, FileSystemEvent from watchdog.events import FileSystemEventHandler, FileSystemMovedEvent, FileSystemEvent
from watchdog.observers.polling import PollingObserver from watchdog.observers.polling import PollingObserver
@@ -67,6 +68,9 @@ class Monitor(metaclass=Singleton):
# 存储过照间隔(分钟) # 存储过照间隔(分钟)
_snapshot_interval = 5 _snapshot_interval = 5
# TTL缓存,10秒钟有效
_cache = TTLCache(maxsize=1024, ttl=10)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.transferchain = TransferChain() self.transferchain = TransferChain()
@@ -215,6 +219,10 @@ class Monitor(metaclass=Singleton):
""" """
# 全程加锁 # 全程加锁
with lock: with lock:
# TTL缓存控重
if self._cache.get(str(event_path)):
return
self._cache[str(event_path)] = True
try: try:
# 开始整理 # 开始整理
self.transferchain.do_transfer( self.transferchain.do_transfer(