gpt4 book ai didi

python - 收到 celery 任务但未执行

转载 作者:太空狗 更新时间:2023-10-29 21:09:28 26 4
gpt4 key购买 nike

我有收到但不会执行的 Celery 任务。我正在使用 Python 2.7 和 Celery 4.0.2。我的消息代理是 Amazon SQS。

这是 celery worker 的输出:

$ celery worker -A myapp.celeryapp --loglevel=INFO
[tasks]
. myapp.tasks.trigger_build

[2017-01-12 23:34:25,206: INFO/MainProcess] Connected to sqs://13245:**@localhost//
[2017-01-12 23:34:25,391: INFO/MainProcess] celery@ip-111-11-11-11 ready.
[2017-01-12 23:34:27,700: INFO/MainProcess] Received task: myapp.tasks.trigger_build[b248771c-6dd5-469d-bc53-eaf63c4f6b60]

我尝试在运行 celery worker 时添加 -Ofair 但这没有帮助。其他一些可能有用的信息:

  • Celery 总是收到 8 个任务,尽管有大约 100 条消息等待接收。
  • 大约每 4 到 5 次任务就会运行并完成,但随后又会卡住。
  • 这是ps aux 的结果。请注意,它在 3 个不同的进程中运行 celery(不确定为什么),其中一个进程的 CPU 使用率为 99.6%,即使它没有完成任何任务或任何事情。

进程:

$ ps aux | grep celery
nobody 7034 99.6 1.8 382688 74048 ? R 05:22 18:19 python2.7 celery worker -A myapp.celeryapp --loglevel=INFO
nobody 7039 0.0 1.3 246672 55664 ? S 05:22 0:00 python2.7 celery worker -A myapp.celeryapp --loglevel=INFO
nobody 7040 0.0 1.3 246672 55632 ? S 05:22 0:00 python2.7 celery worker -A myapp.celeryapp --loglevel=INFO

设置:

CELERY_BROKER_URL = 'sqs://%s:%s@' % (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY.replace('/', '%2F'))
CELERY_BROKER_TRANSPORT = 'sqs'
CELERY_BROKER_TRANSPORT_OPTIONS = {
'region': 'us-east-1',
'visibility_timeout': 60 * 30,
'polling_interval': 0.3,
'queue_name_prefix': 'myapp-',
}
CELERY_BROKER_HEARTBEAT = 0
CELERY_BROKER_POOL_LIMIT = 1
CELERY_BROKER_CONNECTION_TIMEOUT = 10

CELERY_DEFAULT_QUEUE = 'myapp'
CELERY_QUEUES = (
Queue('myapp', Exchange('default'), routing_key='default'),
)

CELERY_ALWAYS_EAGER = False
CELERY_ACKS_LATE = True
CELERY_TASK_PUBLISH_RETRY = True
CELERY_DISABLE_RATE_LIMITS = False

CELERY_IGNORE_RESULT = True
CELERY_SEND_TASK_ERROR_EMAILS = False
CELERY_TASK_RESULT_EXPIRES = 600

CELERY_RESULT_BACKEND = 'django-db'
CELERY_TIMEZONE = TIME_ZONE

CELERY_TASK_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['application/json']

CELERYD_PID_FILE = "/var/celery_%N.pid"
CELERYD_HIJACK_ROOT_LOGGER = False
CELERYD_PREFETCH_MULTIPLIER = 1
CELERYD_MAX_TASKS_PER_CHILD = 1000

报告:

$ celery report -A myapp.celeryapp

software -> celery:4.0.2 (latentcall) kombu:4.0.2 py:2.7.12
billiard:3.5.0.2 sqs:N/A
platform -> system:Linux arch:64bit, ELF imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:sqs results:django-db

最佳答案

首先安装eventlet,


> pip install eventlet

然后运行


> celery -A myapp.celeryapp worker --loglevel=info -P eventlet

关于python - 收到 celery 任务但未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41636273/

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