mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-09 05:18:03 +08:00
refactor: wrap start function execution in try-except block
Improve error handling by catching Failed exceptions during the run and ensuring the running flag is properly released on failure. This prevents the application from remaining in a locked state after critical errors.
This commit is contained in:
parent
3a468c591b
commit
a1b181511d
2 changed files with 151 additions and 150 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
4.6.3-develop3
|
||||
4.6.3-develop4
|
||||
|
|
|
@ -455,6 +455,8 @@ def start():
|
|||
# Acquire lock only briefly to set the flag, then release immediately
|
||||
with is_running_lock:
|
||||
is_running.value = True # Set flag to indicate a run is in progress
|
||||
|
||||
try:
|
||||
start_time = datetime.now()
|
||||
args["time"] = start_time.strftime("%H:%M")
|
||||
args["time_obj"] = start_time
|
||||
|
@ -569,18 +571,8 @@ def start():
|
|||
body = logger.separator(msg)[0]
|
||||
return body
|
||||
|
||||
try:
|
||||
cfg = Config(default_dir, args)
|
||||
qbit_manager = cfg.qbt
|
||||
except Exception as ex:
|
||||
logger.stacktrace()
|
||||
logger.print_line(ex, "CRITICAL")
|
||||
logger.print_line("Exiting scheduled Run.", "CRITICAL")
|
||||
finished_run(next_scheduled_run_info_shared)
|
||||
# Release flag when config validation fails
|
||||
with is_running_lock:
|
||||
is_running.value = False
|
||||
return None
|
||||
|
||||
if qbit_manager:
|
||||
# Execute qBittorrent commands using shared function with error handling
|
||||
|
@ -615,6 +607,15 @@ def start():
|
|||
with is_running_lock:
|
||||
is_running.value = False
|
||||
logger.info("Released lock for web API requests despite webhook error")
|
||||
except Failed as ex:
|
||||
logger.stacktrace()
|
||||
logger.print_line(ex, "CRITICAL")
|
||||
logger.print_line("Exiting scheduled Run.", "CRITICAL")
|
||||
finished_run(next_scheduled_run_info_shared)
|
||||
# Release flag when any Failed exception occurs during the run
|
||||
with is_running_lock:
|
||||
is_running.value = False
|
||||
return None
|
||||
|
||||
|
||||
def end():
|
||||
|
|
Loading…
Add table
Reference in a new issue