Hey All, thanks for making this such a great forum. I’ve come here to get many answers, this is the first time I’ve had to post a question.
I’ve got a problem with Django+RabbitMQ+Celery on a Windows machine. When I start my worker using:
celery -A string_project worker -l info --pool=solo
It automatically receives a task, indicating that a task is in the queue. When I let it run, it will complete the task, but then automatically start another one. I suspect an acknowledgement isn’t happening and my tasks are not getting deleted from the queue, but I haven’t been able to figure out how to troubleshoot this. It’s a long running task, about 12 minutes. I had this working perfectly last week, updated plots to use Plotly, and now this seemingly unrelated issue cropped up. Here’s my setup:
settings.py:
# Celery Config
CELERY_BROKER_URL = 'amqp://localhost'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_AMQP_TASK_RESULT_EXPIRES = 1000
CELERY_ACKS_LATE=False
CELERY_TASK_TRACK_STARTED=True
CELERY_SEND_TASK_EVENTS=True
celery.py:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery 
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'string_project.settings')
app = Celery('string_project')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
init.py:
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__=['celery_app']
models.py
from django.db import models
from django.contrib.auth import get_user_model
from django.conf import settings
from datetime import date
from django.urls import reverse
# Create your models here.
class Application(models.Model):
	CATEGORY_CHOICES = (
		('S', 'Should Cost'),
		('D', 'Demand Prediction'),
		('C', 'Quote Optimizer'),
	)
	company=models.CharField(max_length=100, default="")
	category = models.CharField(max_length=1, choices=CATEGORY_CHOICES, default="")
	title=models.CharField(max_length=100)
	description = models.TextField(max_length=250)
	filepath = models.TextField(default="")
	date_created = models.DateTimeField(auto_now_add=True, null=True, blank=True)
	creator = models.ForeignKey(
		get_user_model(),
		on_delete=models.CASCADE,
	)
	#Additional information I need to add to the model so I can quickly view a completed analysis
	raw_data_table = models.TextField(default="", blank=True)
	result_table = models.TextField(default="", blank=True)
	feat_imp_fig = models.TextField(default="", blank=True)
	predictions_fig = models.TextField(default="", blank=True)
	top_ten = models.TextField(default="", blank=True)
	run_date = models.DateTimeField(auto_now=True, null=True, blank=True)
	def __str__(self):
		return self.description
	def get_absolute_url(self):
		return reverse ('applications')
tasks.py:
@shared_task
def run_should_cost(filepath, logged_in_user):
... #this is a really long machine learning algorithm that ends with saving data to my db here:
	p=Application(
		id=logged_in_user,
		raw_data_table=raw_data_table,
		result_table=result_table,
		feat_imp_fig=feat_imp_fig,
		predictions_fig=predictions_fig,
		top_ten=top_ten,
		run_date=current_time
		)
	p.save(update_fields=['raw_data_table', 'result_table', 'feat_imp_fig', 'predictions_fig', 'top_ten', 'run_date'])
views.py:
class ShouldCostRunView(CompanyCheckMixin, DetailView):
	model=Application
	template_name='submit_success.html'
	def get_context_data(self, **kwargs):
		context=super(ShouldCostRunView, self).get_context_data(**kwargs)
		filepath=self.object.filepath
		logged_in_user=self.object.pk
		run_should_cost.delay(filepath, logged_in_user)
		return context
Any help would be appreciated!