Skip to content

Commit

Permalink
fix 目录监控控重
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Dec 31, 2024
1 parent bb478c9 commit 4b3f04c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 2 additions & 5 deletions app/chain/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,8 @@ class TransferChain(ChainBase, metaclass=Singleton):
# 文件整理线程
_transfer_thread = None

# 队列等待时间(秒)
_queue_timeout = 5

# 队列间隔时间(秒)
_transfer_interval = 10
_transfer_interval = 15

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -536,7 +533,7 @@ def __start_transfer(self):

while not global_vars.is_system_stopped:
try:
item: TransferQueue = self._queue.get(timeout=self._queue_timeout)
item: TransferQueue = self._queue.get(block=False)
if item:
task = item.task
if not task:
Expand Down
8 changes: 8 additions & 0 deletions app/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

from apscheduler.schedulers.background import BackgroundScheduler
from cachetools import TTLCache
from watchdog.events import FileSystemEventHandler, FileSystemMovedEvent, FileSystemEvent
from watchdog.observers.polling import PollingObserver

Expand Down Expand Up @@ -67,6 +68,9 @@ class Monitor(metaclass=Singleton):
# 存储过照间隔(分钟)
_snapshot_interval = 5

# TTL缓存,10秒钟有效
_cache = TTLCache(maxsize=1024, ttl=10)

def __init__(self):
super().__init__()
self.transferchain = TransferChain()
Expand Down Expand Up @@ -215,6 +219,10 @@ def __handle_file(self, storage: str, event_path: Path, file_size: float = None)
"""
# 全程加锁
with lock:
# TTL缓存控重
if self._cache.get(str(event_path)):
return
self._cache[str(event_path)] = True
try:
# 开始整理
self.transferchain.do_transfer(
Expand Down

0 comments on commit 4b3f04c

Please sign in to comment.