我有以下路线,根据 POST 请求执行特定任务并将计数增加 1。
@blueprint.route("Calendar", methods=['GET', 'POST'])
def Calendar():
count +=1
email = request.json.get('email')
therestart(email)
return email
我想为每个用户每 24 小时重置一次计数,因此我想到的最好方法是执行后台调度程序:
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()
这给出了一个错误:
ValueError: The following arguments have not been supplied: email
这是有道理的,但同时,如果我将其更改为这样的内容:
def therestart(email):
if email:
scheduler()
def scheduler()
scheduler = BackgroundScheduler()
scheduler.add_job(func=therestart, trigger="interval", seconds=3)
scheduler.start()
然后每次电子邮件被传递或激活时,scheduler()
都会执行这违背了我的目标。
如果有人能将我从这个困境中拯救出来,我将非常感激。
最佳答案
我最终做了:
def restart():
users = User.query.all()
for user in users:
if user.stripeSubscriptionId is None:
user.count = 1
db.session.commit()
return ''
关于python - 值错误: The following arguments have not been supplied: email,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65552722/