推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dwadewyp
V2EX  ›  Python

celery 中一个定时任务的 state 一直是 started, 此任务并未执行 有可能什么原因

  •  
  •   dwadewyp · Aug 21, 2019 · 2293 views
    This topic created in 2469 days ago, the information mentioned may be changed or developed.

    目前可知 1.这个任务执行时间较长,同步方式执行了一下在生产环境大概一两个小时,所以推测 有可能是任务执行过长 直接 timeout,不过查看了下 定时任务并没有设置类似于 timeout 的参数 2.在 celery 的日志中 可以查看到 broker 已经 send 了这个任务 并且 worker 也 receive 到这个任务,不过没有 successed 的 log. 有没有可能 queue 消费了 不过 worker 执行时出现的问题? 有木有一些好的排查方式 提供下?

    6 replies    2019-08-22 15:56:47 +08:00
    jenlors
        1
    jenlors  
       Aug 21, 2019
    就是任务执行时间过长了,celery 有 time_limit 和 soft_time_liimit 两个配置你可以看一下。
    marco25
        2
    marco25  
       Aug 21, 2019
    worker 里面加点 log 打印出来看看到哪里了?
    dwadewyp
        3
    dwadewyp  
    OP
       Aug 21, 2019
    @long2ice 我这边配置没有加 time_limit 单个任务也没有加 soft_time_limit, 能不能是 worker 执行过长 自动挂起了
    jesnridy
        4
    jesnridy  
       Aug 21, 2019
    是不是负载均衡导致的,默认负载方式是预取操作,会导致一个 worker 正在运行耗时的任务,另一个任务也被分配到这个 worker 必须等待前面一个任务执行完才能执行,即使其他 worker 是空闲的,启动参数加个-Ofair 试试
    vZexc0m
        5
    vZexc0m  
       Aug 21, 2019
    不知道是不是因为消费者进程假死的问题导致的。以前也遇到过消费者不执行任务的问题,后来切换到 dramatiq 就没问题了。
    hanssx
        6
    hanssx  
       Aug 22, 2019
    我之前这个参数是 True,立即任务的状态一直是 PENDING,你看看这个
    CELERY_IGNORE_RESULT = False # 是否需要关注任务执行状态,如果设置为 True,任务状态会一直是 PENDING,为啥呢???

    另外,任务执行时间长,celery 任务还真有执行时间限制?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1165 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 23:14 · PVG 07:14 · LAX 16:14 · JFK 19:14
    ♥ Do have faith in what you're doing.