我一直在尝试安排芹菜在后台执行的任务,但我一直遇到问题。
到目前为止我所做的快速参考
我安装celery
并django-celery
通过easy_install
,添加到INSTALLED_APPS
:
'djcelery',
'kombu.transport.django',
导入以下内容并运行syncdb:
import djcelery
djcelery.setup_loader()
BROKER_URL = "django://"
我试图在后台运行的任务是密码重置。因此,当用户忘记密码时,我想让发送电子邮件任务在后台运行,所以我所做的就是将我的 forgot_password 函数从其中views.py
移入tasks.py
,以便它可以运行。
我的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')
他们views.py
现在什么都没有。
问题是,即使我丢失了密码,我也可以发送电子邮件。我不确定它是否在后台运行。我所做的检查是:
manage.py celery worker --loglevel=info
但我收到一个错误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'
有人可以告诉我是否将忘记密码配置为在后台发送电子邮件以及为什么会出现此错误,请帮助我KeyError: 'processName'
?