Maaroufabousaleh commited on
Commit
58c5ce0
·
1 Parent(s): 4b5719e

Enhance health status check to handle malformed last_run values and improve logging

Browse files
Files changed (1) hide show
  1. src/api/gradio_main.py +13 -4
src/api/gradio_main.py CHANGED
@@ -53,10 +53,19 @@ def get_health_status():
53
  if os.path.exists(last_run_file):
54
  with open(last_run_file, 'r') as f:
55
  last_run_str = f.read().strip()
56
- last_run = datetime.strptime(last_run_str, '%Y-%m-%d %H:%M:%S')
57
- time_since_last_run = (datetime.now() - last_run).total_seconds()
58
- scheduler_running = time_since_last_run < 2700 # 45 minutes
59
- last_run_time = last_run_str
 
 
 
 
 
 
 
 
 
60
  except Exception as e:
61
  logger.warning(f"Could not check scheduler status: {e}")
62
 
 
53
  if os.path.exists(last_run_file):
54
  with open(last_run_file, 'r') as f:
55
  last_run_str = f.read().strip()
56
+ if last_run_str:
57
+ try:
58
+ last_run = datetime.strptime(last_run_str, '%Y-%m-%d %H:%M:%S')
59
+ time_since_last_run = (datetime.now() - last_run).total_seconds()
60
+ scheduler_running = time_since_last_run < 2700 # 45 minutes
61
+ last_run_time = last_run_str
62
+ except Exception:
63
+ logger.debug("Malformed last_run value: %s", last_run_str)
64
+ scheduler_running = False
65
+ last_run_time = "Unknown"
66
+ else:
67
+ scheduler_running = False
68
+ last_run_time = "Unknown"
69
  except Exception as e:
70
  logger.warning(f"Could not check scheduler status: {e}")
71