我正在建立一个可以在线访问的潜在客户开发门户。请不要介意代码的冗长,我现在正在进行大量调试。
我的celery 工人不停地接分配给它的任务,我不知道为什么。
奇怪的是,有时它的工作效率是100%完美:终端中从来没有任何显式错误。
我目前在debug=true和redis中担任代理!
celery 启动工人终端命令与响应
celery -A mysite worker -l info --pool=solo
-------------- celery@DESKTOP-OG8ENRQ v5.0.2 (singularity)
---*****-----
--*******---- Windows-10-10.0.19041-SP0 2020-11-09 00:36:13
-***--- * ---
-**---------- [config]
-**---------- .> app: mysite:0x41ba490
-**---------- .> transport: redis://localhost:6379//
-**---------- .> results: redis://localhost:6379/
-***--- * --- .> concurrency: 12 (solo)
--*******---- .> task events: OFF (enable -E to monitor tasks in this worker)
---*****-----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. mysite.celery.debug_task
. submit
[2020-11-09 00:36:13,899: INFO/MainProcess] Connected to redis://localhost:6379//
[2020-11-09 00:36:14,939: WARNING/MainProcess] c:\users\coole\pycharmprojects\lead_django_retry\venv\lib\site-packages\celery\app\control.py:48: DuplicateNodenameWarning: Received multiple replies from node name: celery@DESKTOP-OG8ENRQ.
Please make sure you give each node a unique nodename using
the celery worker `-n` option.
warnings.warn(DuplicateNodenameWarning(
[2020-11-09 00:36:14,939: INFO/MainProcess] mingle: all alone
[2020-11-09 00:36:14,947: INFO/MainProcess] celery@DESKTOP-OG8ENRQ ready.
视图.py
class LeadInputView(FormView):
template_name = 'lead_main.html'
form_class = LeadInput
def form_valid(self, form):
print("I'm at views")
form.submit()
print(form.submit)
return HttpResponseRedirect('./success/')
任务.py
@task(name="submit")
def start_task(city, category, email):
print("I'm at tasks!")
print(city, category, email)
"""sends an email when feedback form is filled successfully"""
logger.info("Submitted")
return start(city, category, email)
表单.py
class LeadInput(forms.Form):
city = forms.CharField(max_length=50)
category = forms.CharField(max_length=50)
email = forms.EmailField()
def submit(self):
print("I'm at forms!")
x = (start_task.delay(self.cleaned_data['city'], self.cleaned_data['category'], self.cleaned_data['email']))
return x
celery .py
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
app = Celery('mysite')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
设置.py
BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'UTC'
runserver终端将如下所示:
I'm at views
I'm at forms!
<bound method LeadInput.submit of <LeadInput bound=True, valid=True, fields=(city;category;email)>>
但工人没有说捡到什么,只是说celery@desktop-og8enrq 准备好了。“除非,当它真的起作用的时候。。。不知为什么?我不知所措!
2条答案
按热度按时间hfyxw5xn1#
见到这个的人都好。原来,这是celery 的虫子(或者是redis?)。。。显然很多windows用户都会遇到这种情况。https://github.com/celery/celery/issues/3759
事实证明,答案是在启动worker时让-p单独运行。我不知道为什么会这样。。。但这就解决了!
谢谢你的帮助!你让我找到了解决办法。
o0lyfsai2#
默认情况下,如果您愿意在同一主机中使用多个worker,那么celery 将使用主机名作为worker name,然后指定
-n
选项。您的代码工作正常,但任务已传递给第一个工作进程,请参阅DuplicateNodeWarning with Now Simplific reason#2938