Answer the question
In order to leave comments, you need to log in
Сonsumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [WinError 10061] Connection not established... Who can help?
Followed instructions for connecting celery here. At first everything worked, tasks got into the queue, but were not executed. Reinstalled celery (more modern version) - everything stopped working. I tried to reinstall the broker and different versions of celery, the result is the same. Searched for a lot of information in search engines - nothing helped. Who can tell? I'll give you some code.
Successfully installed amqp-5.0.5 billiard-3.6.3.0 celery-5.0.5 kombu-5.0.2 vine-5.0.0
celery.py
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kosmetica.settings')
app = Celery('kosmetica')<code></code>app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
from kosmetica.celery import app
from django.core.mail import send_mail
from .models import Order
@app.task
def order_created(order_id):
"""
Задача для отправки уведомления по электронной почте при успешном создании заказа.
"""
order = Order.objects.get(id=order_id)
subject = 'Заказ №. {}'.format(order_id)
message = 'Добрый день! {},\n\nВы успешно сформировали заказ.\
Ваш заказ № {}.'.format(order.first_name,
order.id)
mail_sent = send_mail(subject,
message,
'[email protected]',
[order.email])
return mail_sent
from . import views
urlpatterns = [
url(r'^create/$', views.order_create, name='order_create'),
]
from cart.cart import Cart
from .tasks import order_created
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# очистка корзины
cart.clear()
# запуск асинхронной задачи
order_created.delay(order.id)
return render(request, 'orders/order/created.html',
{'order': order})
else:
form = OrderCreateForm
return render(request, 'orders/order/create.html',
{'cart': cart, 'form': form})
Answer the question
In order to leave comments, you need to log in
And what is this port 5672? There is no such port in the list.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question