为什么Celery任务状态在PENDING和STARTED之间交替显示?

时间:2018-09-05 12:55:56

标签: heroku rabbitmq celery cloudamqp

我正在使用芹菜在工人上部署烧瓶应用程序,其中概述了一些配置:

celery.conf.task_time_limit = 99
celery.conf.task_track_started = True
# recommended settings by CloudAMQP...
celery.conf.broker_pool_limit = 3             # Will decrease connection usage
celery.conf.broker_heartbeat = None           # if None: We're using TCP keep-alive instead
celery.conf.broker_connection_timeout = 30    # May require a long timeout due to Linux DNS timeouts etc
celery.conf.event_queue_expires = 60          # Will delete all celeryev. queues without consumers after 1 minute.
celery.conf.worker_prefetch_multiplier = 1    # Disable prefetching, it's causes problems and doesn't help performance
celery.conf.result_expires = 40000            # half a day expiry for backend result messages

broker_url = 'amqp://guest:guest@localhost:5672//'  # real values in production.
result_backend = 'rpc://'

在客户端浏览器中通过AJAX api URL启动单个异步任务后,然后我开始使用task.id进行轮询以检查其完成情况。通常需要大约10秒钟...

var apiGetStatus = function() {
self = this;
$.ajax({
    dataType: "json",
    url: self.calcApiIdUrl,
    method: "GET",
    data: {},
    success: function (data) {

        console.log("DEV: url: ", self.calcApiIdUrl);
        console.log('DEV: long polling data state..', data["state"]);

        if (data["state"] != "PENDING" && data["state"] != "STARTED") {
            if (data["state"] == "SUCCESS") {
                // good.
                self.calcApiStatus = data["status"];
            } else {
                // bad.
                self.calcApiStatus = data["status"]
            }
        } else {
            // continue polling in 1 second..
            self.calcApiStatus = data["status"];
            setTimeout(function () {
                self.apiGetStatus();
            }, 1000);
        }
    },
    error: function () {
        // handle.
    }
}) 
}

当我在使用RabbitMQ服务器的本地服务器上在开发中执行此操作时,我将任务的状态最初定为PENDING,然后它变为STARTED并一直保持到成功。

当我使用cloudAMQP作为代理在Heroku上执行此任务时,任务状态在PENDING和STARTED之间振荡,但是日志并没有表明该任务正在重复执行,实际上它似乎已被报告为PENDING。当我将Redis用作result_backend时,不会出现此错误。

有人想为什么会发生这种交替吗?我没主意。enter image description here

0 个答案:

没有答案