fix: reset state when starting new source run

This commit is contained in:
2026-05-22 20:51:48 +04:00
parent 45f56bc146
commit 6f3637795b
2 changed files with 19 additions and 0 deletions

View File

@@ -71,6 +71,7 @@ def main():
if args.mode == "source":
from source.source import run_source_mode
state.reset_state(mode="source")
try:
run_source_mode()
except KeyboardInterrupt:

View File

@@ -127,6 +127,24 @@ def clear_error():
save_state(state)
def reset_state(mode=None):
"""Сбрасывает состояние для нового запуска (source, target или полностью)."""
global _LAST_STATE
# Загружаем текущее, чтобы не потерять пути к архивам если пользователь хочет
# Но completed_steps и stage сбрасываем
state = load_state()
state["stage"] = "INIT"
state["mode"] = mode
state["completed_steps"] = []
state["interrupted_at"] = None
state["resumable_hint"] = None
state["last_error"] = None
state["paused"] = False
state["updated_at"] = datetime.now().isoformat()
_LAST_STATE = state
save_state(state)
def set_interrupted():
"""Помечает, что скрипт был прерван (Ctrl+C, SIGTERM)."""
state = load_state()