dbader / schedule

Python job scheduling for humans.
https://schedule.readthedocs.io/
MIT License
11.73k stars 959 forks source link

Generating future run times (simulating) #504

Closed trippy22 closed 2 years ago

trippy22 commented 2 years ago

I'm interested in scheduling tasks at random times of the day. This seems like it does the job currently, from the docs:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(5).to(10).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

I was however curious in gaining more insight about what future times this task would run, in sorts, a "simulation" of future times selected without actually waiting for the task to execute. Is this something that's possible to mock out?

trippy22 commented 2 years ago

Basically, I'd expect some sort of outputs for date times if I were to run a simulation for say the next 10 executions:

2021-12-29 22:02:36.618341
2021-12-29 22:16:37.301015
2021-12-29 22:33:37.309914
2021-12-29 22:50:37.489636
2021-12-29 23:06:37.598328
2021-12-29 23:23:38.258891
2021-12-29 23:34:39.044151
2021-12-29 23:51:39.051819
2021-12-30 00:07:39.652380
2021-12-30 00:17:39.767334
trippy22 commented 2 years ago

I was able to achieve this by reusing the tests here:

https://github.com/dbader/schedule/blob/aa215bbbdb3d043c37d49b6077a51a60f986b820/test_schedule.py#L199