|
20 | 20 | response = requests.get('http://localhost:5001/settings/persist_logs', timeout=10) |
21 | 21 | state = response.json() |
22 | 22 |
|
23 | | - if state["persist_logs"] and state["auto_off_delay"] > 0: |
24 | | - body: dict |
25 | | - if state["auto_off_delay"] >= 1: |
26 | | - delay = state["auto_off_delay"] - 1 |
27 | | - body = { |
28 | | - "persist_logs": True, |
29 | | - "auto_off_delay": delay, |
30 | | - } |
| 23 | + future_persist_state = state["auto_off_delay"] != 1 |
| 24 | + delay = state["auto_off_delay"] - 1 |
| 25 | + body = { |
| 26 | + "persist_logs": future_persist_state, |
| 27 | + "auto_off_delay": delay if future_persist_state else 14, # If no longer persisting, set to default |
| 28 | + } |
| 29 | + json_data = json.dumps(body) |
| 30 | + response = requests.post( |
| 31 | + url='http://localhost:5001/settings/persist_logs', |
| 32 | + headers={'Content-Type': 'application/json'}, |
| 33 | + data=json_data, |
| 34 | + timeout=10, |
| 35 | + ) |
| 36 | + |
| 37 | + if response.ok: |
| 38 | + loop = False |
| 39 | + if future_persist_state: |
31 | 40 | logging.info(f"Persist logs will be automatically turned off in {delay} day(s)") |
32 | 41 | else: |
33 | | - body = { |
34 | | - "persist_logs": False, |
35 | | - "auto_off_delay": 14, # Reset to default for next time |
36 | | - } |
37 | 42 | logging.info("Persist logs has been turned off automatically") |
38 | | - |
39 | | - json_data = json.dumps(body) |
40 | | - response = requests.post( |
41 | | - url='http://localhost:5001/settings/persist_logs', |
42 | | - headers={'Content-Type': 'application/json'}, |
43 | | - data=json_data, |
44 | | - timeout=10, |
45 | | - ) |
46 | | - |
47 | | - if response.ok: |
48 | | - loop = False |
49 | 43 | except Exception as exc: |
50 | | - logger.exception(f"Auto off increment has failed with the following exception, trying again in 5 seconds: {exc}") |
| 44 | + logger.exception(f"increment_auto_off.py has failed with the following exception, trying again in 5 seconds: {exc}") |
51 | 45 | finally: |
52 | 46 | if loop: |
53 | 47 | time.sleep(5) # Loop until there is a response.ok at the end |
0 commit comments