最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Celery中如何指定延期多长时间后再运行任务

celery crifan 4677浏览 0评论

折腾:

【已解决】Flask中如何保存临时文件且可以指定有效期

期间,在:

基于 Celery 的后台任务 — Flask 0.10.1 文档

中看到:

result.wait()

不知道如何指定延期时间

celery wait time

celery.result — Celery 4.1.0 documentation

Calling Tasks — Celery 4.1.0 documentation

python – Celery workers wait – Stack Overflow

celery task using wait()

celery 指定 延期时间

celery 4.1.0 版本定时任务执行时间 bug | 阿小信的博客

Django Celery定时任务和时间设置 – 杨仕航的博客

Celery(四)定时任务 – 再见紫罗兰 – 博客园

使用 Celery 和 redis 完成任务队列 | Simple and Interesting

celery例子实现定时发送邮件-新掌门-51CTO博客

celery 指定 delay时间 执行

celery 延期 特定时间 执行

异步任务神器 Celery | FunHacks

“apply_async 常用的参数如下:

* countdown:指定多少秒后执行任务

task1.apply_async(args=(2, 3), countdown=5) # 5 秒后执行任务

* eta (estimated time of arrival):指定任务被调度的具体时间,参数类型是 datetime

from datetime import datetime, timedelta

# 当前 UTC 时间再加 10 秒后执行任务

task1.multiply.apply_async(args=[3, 7], eta=datetime.utcnow() + timedelta(seconds=10))”

终于找到了:

要么用:countdown,要么用eta

celery.app.task — Celery 4.1.0 documentation

“* countdown (float) – Number of seconds into the future that the task should execute. Defaults to immediate execution.

* eta (datetime) – Absolute time and date of when the task should be executed. May not be specified if countdown is also supplied.”

注意此处不是去用:

“* expires (float, datetime) – Datetime or seconds in the future for the task should expire. The task won’t be executed after the expiration time.”

【总结】

可以参考Celery官网文档中去:

  • 要么用countdown指定多少秒之后任务再执行

  • 要么用eta指定精确的时间datetime后任务再运行

    • 如果设置了countdown,则明显没必要再设置eta参数了

注意:此处不是用expires

因为expires指的是:过了多长时间之后,你要运行的任务就过期了

而过期了的任务,Celery就不会去运行了。

转载请注明:在路上 » 【已解决】Celery中如何指定延期多长时间后再运行任务

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.164 seconds, using 22.16MB memory