This is a followup queston from here.
Django 1.3.1, celery 2.2.7, python2.6.
I have the following in the fruits/models.py
:
Consider the model:
class Fruit(models.Model):
name = models.CharField(max_length=50)
def __unicode__(self):
return self.name
And the following in the fruits/tasks.py
:
from django.dispatch import receiver
from django.db.models import signals
from celery.task import periodic_task, task
import fruits.models as m
import time
@task()
def check_fruit(id):
time.sleep(2)
try:
fruit = m.Fruit.objects.get(pk=id)
print "Fruit %s is found!" % fruit.name
except m.Fruit.DoesNotExist:
print "no such fruit"
@receiver(signals.pre_save, sender=m.Fruit, dispatch_uid="on_fruit_save")
def on_custom_feed_save(sender, instance, **kwargs):
check_fruit.apply_async(args=[instance.id])
I launch celery daemon, then open django shell and type:
import fruits.tasks;
import fruits.models as m;
m.Fruit(name="plum").save()
Question: I would expect that the task would find the fruit, but it never does. Why?
(I'm launching task from pre-save signal on purpose to simulate a problem that happens on a large system).