Skip to content

Commit

Permalink
Bugfix: Apply schedule did not retry when error occurred
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleshot committed Apr 9, 2024
1 parent 3083211 commit 9f54afe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions witty_pi_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ def generate_schedule(start_hour: int, start_minute: int, interval_length_minute

def apply_schedule(self, max_retries: int = 5) -> str:
'''Apply schedule to Witty Pi 4'''
for _ in range(max_retries):
for retry in range(max_retries):
try:
# Apply new schedule
command = f"cd {WITTYPI_DIRECTORY} && sudo ./runScript.sh"
output = check_output(command, shell=True, executable="/bin/bash", stderr=STDOUT, universal_newlines=True, timeout=10)
output = check_output(command, shell=True, executable="/bin/bash", stderr=STDOUT, universal_newlines=True, timeout=15)
output = output.split("\n")[1:3]

if "Schedule next startup at:" in output[1]:
Expand All @@ -220,10 +220,12 @@ def apply_schedule(self, max_retries: int = 5) -> str:

logging.warning("Failed to apply schedule: %s", output[0])
self.sync_time_with_network()

except Exception as e:
logging.error("Failed to apply schedule: %s", str(e))
return "-"
logging.error("Failed to apply schedule: %s (%s)", str(e), retry)

# Return error if max retries reached
return "-"

if __name__ == "__main__":

Expand Down

0 comments on commit 9f54afe

Please sign in to comment.