I have the following route that upon POST request performs a certain task & increase count by 1.
@blueprint.route("Calendar", methods=['GET', 'POST'])
def Calendar():
count +=1
email = request.json.get('email')
therestart(email)
return email
I'd like to reset the count every 24 hours per individual user basis, so the best way that came to my mind was to do a background scheduler:
import atexit
from apscheduler.schedulers.background import BackgroundScheduler
def therestart(email):
if email:
user = User.query.filter_by(email=email).first()
user.count = 0
return 'no email'
scheduler = BackgroundScheduler()
scheduler.add_job(func=therestart, trigger="interval", seconds=200) #change to 86400 sec in prod
scheduler.start()
which gives an error:
ValueError: The following arguments have not been supplied: email
which makes sense but at the same time, if I were to change it to something like this:
def therestart(email):
if email:
scheduler()
def scheduler()
scheduler = BackgroundScheduler()
scheduler.add_job(func=therestart, trigger="interval", seconds=3)
scheduler.start()
then every time email gets passed or activated, scheduler() performs which is against my goal.
Would really appreciate if someone can save me from this dilemma.