mengfoong123 commited on
Commit
fa6afcc
·
verified ·
1 Parent(s): cb439ed

update status to next step

Browse files
Files changed (1) hide show
  1. main.py +16 -3
main.py CHANGED
@@ -13,10 +13,23 @@ last_runs: dict[str, str] = {}
13
  async def root():
14
  return {"message": "Scheduler Space is running. Use /schedule_every5_multiple/"}
15
 
16
- # Status endpoint to view last run times
17
- @app.get("/status/")
18
  async def status():
19
- return {"last_runs": last_runs}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  # Initialize and start the scheduler
22
  scheduler = BackgroundScheduler()
 
13
  async def root():
14
  return {"message": "Scheduler Space is running. Use /schedule_every5_multiple/"}
15
 
16
+ # Status endpoint to view last run and next run times\ n@app.get("/status/")
 
17
  async def status():
18
+ tz = timezone(timedelta(hours=8)) # GMT+08
19
+ next_runs: dict[str, str] = {}
20
+ for job in scheduler.get_jobs():
21
+ # Only include our scheduled jobs (ids start with every5_)
22
+ if job.id.startswith("every5_"):
23
+ url = job.args[0]
24
+ # next_run_time is a datetime in UTC or tz-aware
25
+ nrt = job.next_run_time
26
+ # convert to GMT+08
27
+ if nrt.tzinfo:
28
+ nrt_local = nrt.astimezone(tz)
29
+ else:
30
+ nrt_local = nrt.replace(tzinfo=timezone.utc).astimezone(tz)
31
+ next_runs[url] = nrt_local.isoformat()
32
+ return {"last_runs": last_runs, "next_runs": next_runs}
33
 
34
  # Initialize and start the scheduler
35
  scheduler = BackgroundScheduler()