Spaces:
Sleeping
Sleeping
add path
Browse files
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
|
|
|
|
| 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 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 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()
|