Reputation: 3538
I am using Django, Celery, and Jobtastic to try to set up some tasks that I will be polling for on my main webapp. I am using RabbitMQ as my broker.
The problem is that while the tasks show up properly after starting Celery, attempting to get the status as shown below:
def get_state(request, task_id):
if request.is_ajax():
task = AsyncResult(task_id)
data = task.result or task.state
print(data)
json_data = json.dumps(data)
return JsonResponse(json_data)
I am unable to get any other status but PENDING. My terminal shows that the task has completed yet I still get a PENDING status. I have tried changing the backend below under CELERY_RESULT_BACKEND to multiple backends, including DJCelery, AMQP, and RPC. They all show up properly when launching Celery so I know they are being registered. I also try to start Celery with the --pools=solo option, as suggested for Windows platforms but have not had any luck with that either. Below is my celery.py file where I initialize the celery app.
from __future__ import absolute_import
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'arbitrage.settings')
from django.conf import settings # noqa
app = Celery('arbitrage')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.conf.update(
CELERY_RESULT_BACKEND='amqp',
BROKER_URL='amqp://'
)
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
I instantiate Celery with the following command:
celery -A arbitrage worker -l info --pool=solo
Any help would be greatly appreciated, I am on Celery 3.1.5 as Jobtastic will not function with Celery version >4.0.
Upvotes: 0
Views: 639
Reputation: 3538
Ended up being something completely unrelated. The task_id was invalid when passing it into AsyncResult, thus I was always getting a Pending status since Pending means the status is not known, even for bogus id values.
Upvotes: 1