Friday, January 30, 2015

using celery with django.

I am experimenting with celery with django and i am using windows 7 os on my machine.

Here is outcome... so far.

I added sample app to my project and added tasks.py to my app.
--------------------------------------------------------
tasks.py 
--------------------------------------------------------
from models import SampleCount
from celery import task

@task()
def add_to_count():
    try:
        sc=SampleCount.objects.get(pk=1)
    except:
        sc=SampleCount()
    sc.counter=sc.counter+1
    sc.save()

 ----------------------------------------------------------------------
 models.py 
------------------------------------------------------------------------
from django.db import models

# Create your models here.
class SampleCount(models.Model):
    counter = models.IntegerField(default=0)
    
    
    def __int__(self):
        return self.counter
-------------------------------------------------------------------------------
settings.py
------------------------------------------------------------------------------

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'User_Registration',
    'Location_Management',
    'Drop_Slot_Management',
    'django_extensions',
    'djcelery',
    'kombu.transport.django',
    'sample',
)

BROKER_URL = "django://"

-------------------------------------------------------------------------
Here is what I am doing I am running manage.py shell
importing the model and running the add_to_count() which adds to counter field. 

I run the celeryd from manage.py celeryd. it runs without error

when i run add_to_count.delay().  I get following error in celeryd running prompt. 
  uuid, retval, SUCCESS, request=task_request,
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_met
))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache
  for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\utils\lru_ca
e.py", line 101, in wrapper
  result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 168, in get_models
  self.check_models_ready()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 131, in check_models_ready
  raise AppRegistryNotReady("Models aren't loaded yet.")
pRegistryNotReady: Models aren't loaded yet.

exc, exc_info.traceback)))
015-01-31 09:28:01,621: CRITICAL/MainProcess] Task sample.tasks.add_to_count[f
293be-aaeb-4e32-bbdb-b4a7ba042731] INTERNAL ERROR: AppRegistryNotReady("Models
ren't loaded yet.",)
aceback (most recent call last):
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\app\trace.p
, line 283, in trace_task
  uuid, retval, SUCCESS, request=task_request,
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_met
))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache
  for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\utils\lru_ca
e.py", line 101, in wrapper
  result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 168, in get_models
  self.check_models_ready()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 131, in check_models_ready
  raise AppRegistryNotReady("Models aren't loaded yet.")
pRegistryNotReady: Models aren't loaded yet.
015-01-31 09:29:01,681: WARNING/Worker-1] C:\Python27\lib\site-packages\celery
.1.17-py2.7.egg\celery\app\trace.py:365: RuntimeWarning: Exception raised outs
e body: AppRegistryNotReady("Models aren't loaded yet.",):
aceback (most recent call last):
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\app\trace.p
, line 283, in trace_task
  uuid, retval, SUCCESS, request=task_request,
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_met
))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache
  for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\utils\lru_ca
e.py", line 101, in wrapper
  result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 168, in get_models
  self.check_models_ready()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 131, in check_models_ready
  raise AppRegistryNotReady("Models aren't loaded yet.")
pRegistryNotReady: Models aren't loaded yet.

exc, exc_info.traceback)))
015-01-31 09:29:01,691: CRITICAL/MainProcess] Task sample.tasks.add_to_count[b
fb466-7e18-4aeb-a69d-791222e1aa8e] INTERNAL ERROR: AppRegistryNotReady("Models
ren't loaded yet.",)
aceback (most recent call last):
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\app\trace.p
, line 283, in trace_task
  uuid, retval, SUCCESS, request=task_request,
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_met
))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache
  for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\utils\lru_ca
e.py", line 101, in wrapper
  result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 168, in get_models
  self.check_models_ready()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 131, in check_models_ready
  raise AppRegistryNotReady("Models aren't loaded yet.")
pRegistryNotReady: Models aren't loaded yet.

Am I doing something wrong? 

Regards,
Sarfaraz Ahmed

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b2bec2f1-b849-4247-aca4-aee91be03687%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment