pythonfastapischedule

Python FASTAPI shedule task


I want to write a task that will only run once a day at 3:30 p.m. with Python FASTAPI. How can I do it?

I tried this but it works all the time.

schedule.every().day.at("15:30:00").do(job2)

while True:
    schedule.run_all()

Solution

  • Swap the schedule.run_all() for schedule.run_pending(). It should work!

    import schedule
    import time
    
    def job():
        print("I'm working...")
    
    schedule.every().day.at("15:30:00").do(job)
    
    while True:
        schedule.run_pending()