芹菜工人有时只接任务



我正在构建一个可以在线访问的潜在客户开发门户。请不要介意代码的冗长,我现在正在做很多调试。

我的Celery员工不一致地接受分配给它的任务,我不知道为什么。

奇怪的是,有时它能100%完美地工作:终端中从来没有任何明显的错误。

我目前在DEBUG=TRUE和REDIS作为一个经纪人!

芹菜启动工人终端命令和响应

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:userscoolepycharmprojectslead_django_retryvenvlibsite-packagesceleryappcontrol.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

芹菜.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准备好了"除了,当它真的起作用的时候。。。出于某种原因?我不知所措!

欢迎看到这篇文章的人。事实证明,这是一种芹菜的虫子(或者可能是redis?(。。。显然,许多windows用户都会遇到这种情况。https://github.com/celery/celery/issues/3759

事实证明,答案是在启动worker时使-p单独出现。我不知道为什么会这样。。。但这解决了问题!

感谢Naqib的帮助!你让我找到了一个合适的解决方案。

默认情况下,如果您愿意在同一主机中使用多个工作程序,则芹菜将使用主机名作为工作程序名称,然后指定-n选项。

celery -A mysite worker -l info --pool=solo -n worker2@%h

您的代码运行良好,但任务已传递给第一个工作者,请参阅重复无明显原因的匿名警告#2938

相关内容

  • 没有找到相关文章

最新更新