0

I'm been trying to schedule a task for celery to do at the background but I keep encountering issues.

Quick reference on what I've done so far

I installed celery and django-celery via easy_install, added to INSTALLED_APPS:

'djcelery',
'kombu.transport.django',

imported the following and ran syncdb:

 import djcelery
 djcelery.setup_loader()
 BROKER_URL = "django://"

The task I'm trying to run in the background is password reset. So when a user forget his password , I want to make the sending email task run in the background so what I done is I moved my forgot_password function from views.py into tasks.py so it can run.

My tasks.py:

 from django.contrib.auth.views import password_reset
 from django.shortcuts import render
 from celery.decorators import task

 @task()
 def forgot_password(request):
     if request.method == 'POST':
         return password_reset(request,
             from_email=request.POST.get('email'))
     else:
         return render(request, 'forgot_password.html')

Their nothing in views.py now.

The problem is even though, I can send email if I lose my password. I'm not sure if it's running in the background. What I did to check is was:

 manage.py celery worker --loglevel=info

but I get an error: KeyError: 'processName':

 C:\o\17\mysite>manage.py celery worker --loglevel=info

  -------------- celery@gg-PC v3.0.19 (Chiastic Slide)
 ---- **** -----
 --- * ***  * -- Windows-Vista-6.0.6001-SP1
 -- * - **** ---
 - ** ---------- [config]
 - ** ---------- .> broker:      django://localhost//
 - ** ---------- .> app:         default:0x319c930 (djcelery.loaders.DjangoLoader
 )
 - ** ---------- .> concurrency: 2 (processes)
 - *** --- * --- .> events:      OFF (enable -E to monitor this worker)
 -- ******* ----
 --- ***** ----- [queues]
  -------------- .> celery:      exchange:celery(direct) binding:celery


 [Tasks]
   . accounts.tasks.forgot_password

 [2013-05-15 17:49:45,279: WARNING/MainProcess] C:\Python26\lib\site-packages\dja
 ngo_celery-3.0.17-py2.6.egg\djcelery\loaders.py:133: UserWarning: Using settings
 .DEBUG leads to a memory leak, never use this setting in production environments
 !
   warnings.warn('Using settings.DEBUG leads to a memory leak, never '
 [2013-05-15 17:49:45,292: WARNING/MainProcess] celery@gg-PC ready.
 [2013-05-15 17:49:45,292: INFO/MainProcess] consumer: Connected to django://loca
 lhost//.
 Traceback (most recent call last):
   File "C:\Python26\lib\logging\__init__.py", line 754, in emit
     msg = self.format(record)
   File "C:\Python26\lib\logging\__init__.py", line 637, in format
     return fmt.format(record)
   File "C:\Python26\lib\logging\__init__.py", line 428, in format
     s = self._fmt % record.__dict__
 KeyError: 'processName'
 Traceback (most recent call last):
   File "C:\Python26\lib\logging\__init__.py", line 754, in emit
     msg = self.format(record)
   File "C:\Python26\lib\logging\__init__.py", line 637, in format
     return fmt.format(record)
   File "C:\Python26\lib\logging\__init__.py", line 428, in format
     s = self._fmt % record.__dict__
 KeyError: 'processName'

Can someone please kindly help me by tell me if forget password is configured probably to send emails in the background and why do I get this error KeyError: 'processName'?

1
  • Try manage.py celeryd --loglevel=info Commented May 16, 2013 at 7:06

1 Answer 1

1

First of all there is a simple way of sending emails using celery:

django-celery-email

Second, your task is wrong. Task is a background job, not view. It should perform the final operation. In your case this is sending email

1
  • I did put the task in task.py Commented May 16, 2013 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.