IchBinMichelle
IchBinMichelle

Reputation: 31

Schedule a function at particular time of day using a flask app

I want to schedule (every day at 17:00) a single function in a flask app (my flask app has multiple functions). How can I do that?

from flask import Flask
import schedule
import time

app = Flask(__name__)
app.secret_key = 'my precious'

def fct1():
    print("bla bla bla")

def myfunction():
    print("aaaaaaaaaaaaaaaa")

def programare():
    schedule.every().day.at("17:00").do(fct1)
    while True:
        schedule.run_pending()
        time.sleep(1)

if __name__== '__main__':
    app.run(debug=True)

Upvotes: 0

Views: 709

Answers (1)

eri
eri

Reputation: 3524

Simple thread if server startted standalone:

if __name__== '__main__':
    import threading
    
    threading.Thread(target=programare).start()
    app.run(debug=True)

If server deployed with wsgi or etc I suggest to run shedule separately.

Upvotes: 1

Related Questions