mengfoong123 commited on
Commit
b33cbee
·
verified ·
1 Parent(s): fa6afcc
Files changed (1) hide show
  1. main.py +9 -9
main.py CHANGED
@@ -13,24 +13,24 @@ 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 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()
36
  scheduler.start()
 
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
17
+ @app.get("/status/")
18
  async def status():
19
  tz = timezone(timedelta(hours=8)) # GMT+08
20
  next_runs: dict[str, str] = {}
21
  for job in scheduler.get_jobs():
 
22
  if job.id.startswith("every5_"):
23
  url = job.args[0]
 
24
  nrt = job.next_run_time
25
+ if nrt:
26
+ if nrt.tzinfo:
27
+ nrt_local = nrt.astimezone(tz)
28
+ else:
29
+ nrt_local = nrt.replace(tzinfo=timezone.utc).astimezone(tz)
30
+ next_runs[url] = nrt_local.isoformat()
31
  return {"last_runs": last_runs, "next_runs": next_runs}
32
 
33
+
34
  # Initialize and start the scheduler
35
  scheduler = BackgroundScheduler()
36
  scheduler.start()