gpt4 book ai didi

python - Celery RabbitMQ CloudAMQP 任务队列未在 Heroku 上使用

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

此示例适用于开发环境。在 Heroku 上,任务会排队但不会被消耗。知道我可能做错了什么吗?

RabbitMQ 仪表板显示:

名称参数策略状态就绪未确认总数
1f49ea51a56049f7a68082c6297ea080 Exp D AD HA 空闲 1 0 1 253eb525c95944d2b742f1f112cdc0e5 Exp D AD HA 空闲 1 0 1

过程文件

web: gunicorn hellodjango.wsgi --workers 1
celery: python manage.py celery worker -E --time-limit=1200 --loglevel=ERROR

设置.py

from os import environ
CELERY_RESULT_BACKEND = "amqp"
BROKER_POOL_LIMIT = 0
BROKER_URL = environ.get('CLOUDAMQP_URL', '')
CELERY_TASK_RESULT_EXPIRES = 14400

查看

from django.shortcuts import render
from django.http import HttpResponse
from proj.tasks import add_to_count
from models import SampleCount
import logging
def test_async(request):
sc = add_to_count.delay()
count = SampleCount.objects.all()[0].num
return HttpResponse("test count: %s sc: %s name: %s " %(count,sc,add_to_count.name ))

型号

from django.db import models
# Create your models here.
class SampleCount(models.Model):
num = models.IntegerField(default=0)

任务.py

from __future__ import absolute_import
from celery import shared_task
from proj.models import SampleCount
from celery import task
@task(name='proj.tasks')
def add_to_count():
try:
sc = SampleCount.objects.get(pk=1)
except:
sc = SampleCount()
sc.num = sc.num + 2
sc.save()
return(sc)

最佳答案

我有同样的问题,就我而言,我认为这与命名有关。在您的 procfile 中,您使用的是 manage.py 而 heroku recommend像这样的东西:

worker: celery worker --app=tasks.app

关于python - Celery RabbitMQ CloudAMQP 任务队列未在 Heroku 上使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23328056/

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