gpt4 book ai didi

python - celery ,在指定时间运行一次任务

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:06 24 4
gpt4 key购买 nike

如何在给定时间运行 celery 任务,但只运行一次?

我阅读了文档,但找不到这方面的任何示例。

最佳答案

调用任务时可以使用参数eta。示例:

from datetime import datetime, timedelta

@app.task()
def hello(self):
return 'hello world'


tomorrow = datetime.utcnow() + timedelta(days=1)
hello.apply_async(eta=tomorrow)

文档:http://docs.celeryproject.org/en/latest/userguide/calling.html#eta-and-countdown

或者,当您想多次调用hello并且以确保一次只执行一次时,您可以使用锁定 - 文档中有更多相关信息:http://docs.celeryproject.org/en/latest/tutorials/task-cookbook.html#ensuring-a-task-is-only-executed-one-at-a-time

关于python - celery ,在指定时间运行一次任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41568305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com