python - 值错误: The following arguments have not been supplied: email

标签 python flask cron apscheduler

我有以下路线,根据 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/

相关文章:

python - 无法在 <module 'Word2VecKeyedVectors' > 上获取属性 'gensim.models.keyedvectors'

python - 如何删除 pandas 数据框中的 ['' ]

python - 如何使用 python Flask 将修改后的图像直接上传到 s3 存储桶

python - 如何使用 python Flask 防止长时间运行的工作负载出现 230 秒的 azure 网关超时

python - 如何检查 cronjob 是否在 ubuntu 中运行?

linux - 带有 smartctl 的 Bash 脚本不起作用

python - 值错误 : Can only compare identically-labeled Series objects python

python - 从子词典中获取列表

Heroku 时钟进程 : how to ensure jobs weren't skipped?

python - GET/socket.io/?EIO=3&transport=polling&t=MniHjPM HTTP/1.1