python - 为什么 Python Celery 任务被调用了几次,尽管被调用了一次
问题描述
有这个代码。调用 Celery 任务,它是一个 Python 脚本。想知道为什么我在执行时收到 3 封电子邮件。
test() 被调用了 3 次??????
@client.task()
def test(id):
call(["python", "/script.py", "-t",
"test", "-s", "test", "-o", "real", "-i", "{:s}".format(id)])
message = Mail(
from_email='from',
to_emails='to',
subject="subject {:s}".format(id),
html_content='<strong>text</strong>')
try:
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e.message)
@app.route("/test", methods=['GET'])
@oidc.accept_token(True)
def testbyID():
id = request.args.get('id')
result = test.apply_async(args=[id], countdown=60)
return result.id
处理完任务后,如何更正它以仅收到一封电子邮件?
更新1:
将其更改为
task.delay() 并立即执行任务并仅收到一封电子邮件
仍然想知道如何让它与 1 封电子邮件异步执行?
解决方案
推荐阅读
- python - 无法在 Python 中安装 fancyimpute(适用于 Windows 10)
- node.js - 使用apache2将域名绑定到node.js中的REST API?
- mysql - MySQL中的排序列
- javascript - 如何在按钮单击时添加输入字段
- sql - 根据特定的子字符串短语获取数值
- angular - 调用component.html的插值到component.ts
- javascript - MobX:如何改变一个可观察值以响应另一个值的变化?
- vba - 在 Excel 中没有下一个
- django - 有没有办法在 Django 模型的查询集中隐藏对象?
- php - 经过身份验证的网页(通过 php/html + .htaccess)看不到其他目录(css、JavaScript、图像等)中的资产