fix: _push_cooldown持久化到文件,避免每2分钟重复推送操作区间通知
This commit is contained in:
@@ -333,6 +333,15 @@ def run_once(round_label=""):
|
||||
state_updated = False
|
||||
# 时间冷却:同股同区间30分钟内不重复推
|
||||
_push_cooldown = {}
|
||||
_cooldown_file = "/home/hmo/.hermes/.price_push_cooldown.json"
|
||||
try:
|
||||
import os
|
||||
if os.path.exists(_cooldown_file):
|
||||
with open(_cooldown_file) as _f:
|
||||
_push_cooldown = json.load(_f)
|
||||
except Exception:
|
||||
_push_cooldown = {}
|
||||
|
||||
def _can_push(code, zone_key):
|
||||
now = time.time()
|
||||
key = f"{code}_{zone_key}"
|
||||
@@ -340,6 +349,12 @@ def run_once(round_label=""):
|
||||
if now - last < 1800: # 30分钟
|
||||
return False
|
||||
_push_cooldown[key] = now
|
||||
# 持久化写入
|
||||
try:
|
||||
with open(_cooldown_file, "w") as _f:
|
||||
json.dump(_push_cooldown, _f)
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
|
||||
# 收集所有需要检查的代码
|
||||
|
||||
Reference in New Issue
Block a user