mher / flower

Real-time monitor and web admin for Celery distributed task queue
https://flower.readthedocs.io
Other
6.5k stars 1.09k forks source link

incorrect task state from /api/task/result/* #774

Open leejjoon opened 6 years ago

leejjoon commented 6 years ago

I am trying to use the flower's http api to monitor the task state. But it seems that the task state from the "/api/task/result/*" is incorrect (they never seem to be updated). I only tested this in AMQP with rpc backend. On the other hand, values from "/api/tasks" are okay (what is displayed on the web page is also okay).

Here is a simple script that demonstrate the issue.

from celery import Celery

default_broker = 'pyamqp://guest@localhost//'
app = Celery('task_bug', broker=default_broker, backend='rpc://')

api_root = 'http://localhost:5555/api'
url_root = "http://localhost:5555"

@app.task()
def add(x, y):
    return x + y

def task_state_from_api_task_result(r):
    import requests, json
    task_api = '{}/task'.format(api_root)
    url = "{}/result/{}".format(task_api, r.task_id)
    resp = requests.get(url)

    return resp.json()["state"]

if __name__ == '__main__':

    r = add.delay(3, 4)

    import time
    time.sleep(1)

    assert r.state == "SUCCESS"

    assert task_state_from_api_task_result(r) == "SUCCESS"  # This raises an AssertionError

Here is my environment. I have tested flower 0.9.2 and the current master branch.

software -> celery:4.1.0 (latentcall) kombu:4.1.0 py:2.7.14
            billiard:3.5.0.3 py-amqp:2.2.2
platform -> system:Linux arch:64bit imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:pyamqp results:rpc:///

broker_url: u'amqp://guest:********@localhost:5672//'
result_backend: u'rpc:///'
rvaidya commented 5 years ago

I am experiencing this too

Tasks will also remain PENDING when they are complete if ignore_result=True

Happens in both pip version and development version, using Redis broker/backend.