🛠Maintenance refactor

This commit is contained in:
jokob-sk
2024-06-29 14:39:12 +10:00
parent 709408ca2a
commit 08b163ebe4
26 changed files with 370 additions and 232 deletions

View File

@@ -752,20 +752,24 @@ def check_and_run_user_event(db, all_plugins, pluginsState):
# Check if the log file exists
logFile = os.path.join(logPath, "execution_queue.log")
# track if not an API event
# Track if not an API event and list of executed events
show_events_completed = False
executed_events = []
if not os.path.exists(logFile):
return pluginsState
with open(logFile, "r") as file:
lines = file.readlines()
remaining_lines = []
for line in lines:
# Split the line by '|', and take the third and fourth columns (indices 2 and 3)
columns = line.strip().split('|')[2:4]
if len(columns) != 2:
remaining_lines.append(line)
continue
event, param = columns
@@ -773,19 +777,26 @@ def check_and_run_user_event(db, all_plugins, pluginsState):
if event == 'test':
show_events_completed = True
pluginsState = handle_test(param, db, all_plugins, pluginsState)
if event == 'run':
executed_events.append(f"test with param {param}")
elif event == 'run':
show_events_completed = True
pluginsState = handle_run(param, db, all_plugins, pluginsState)
if event == 'update_api':
# update API endpoints
update_api(db, all_plugins, False, param.split(','))
executed_events.append(f"run with param {param}")
elif event == 'update_api':
# Update API endpoints
update_api(db, all_plugins, False, param.split(','))
executed_events.append(f"update_api with param {param}")
else:
remaining_lines.append(line)
# Clear the log file
open(logFile, "w").close()
# Rewrite the log file with remaining lines
with open(logFile, "w") as file:
file.writelines(remaining_lines)
# only show pop up if not an API event
# Only show pop-up if not an API event
if show_events_completed:
write_notification('[Ad-hoc events] All Events executed', 'interrupt', timeNowTZ())
executed_events_message = ', '.join(executed_events)
write_notification(f'[Ad-hoc events] Events executed: {executed_events_message}', 'interrupt', timeNowTZ())
return pluginsState