0

I have a problem with Celery. I am using Celery with Amazon SQS. I set up everything about Celery and SQS. The function in tasks.py works without delay() but not working with delay().

I succesfully send messages to SQS, i can see my messages in SQS portal in Messages Avaliable section. But they are not receiving by any Celery worker. I suppose that i must see the messages in 'Messages in Flight' section. Here is screenshot:

enter image description here

Here is my views.py where i run the function in tasks.py:

 verify_mail.delay(abcdef@gmail.com)

my tasks.py:

from celery import shared_task
from time import sleep
from django.shortcuts import render, redirect, HttpResponse
import boto3

@shared_task
def verify_mail(new_email):

    ses = boto3.client('ses')

    response = ses.verify_email_identity(
            EmailAddress = new_email
        )

    return None

If i run like that: verify_mail(abcdef@gmail.com), there is no problem. But when i run with delay(), it doesn't working.

I started Celery worker with this code without problem:

celery -A myProject worker -l INFO --without-gossip --without-mingle --without-heartbeat -Ofair --pool=solo

My celery.py:

import os

from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myProject.settings')

app = Celery('myProject')

app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()

@app.task(bind=True, ignore_result=True)
def debug_task(self):
    print(f'Request: {self.request!r}')

My settings.py:

CELERY_BROKER_URL = "sqs://{aws_access_key}:{aws_secret_key}@".format(
    aws_access_key=AWS_ACCESS_KEY_ID, aws_secret_key=AWS_SECRET_ACCESS_KEY
)

CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_BROKER_TRANSPORT_OPTIONS = {
    'region': 'eu-central-1',
}
CELERY_RESULT_BACKEND = None
CELERY_ENABLE_REMOTE_CONTROL = False
CELERY_SEND_EVENTS = False
TFA
  • 59
  • 1
  • 8
  • Does this answer your question? [Celery with Amazon SQS](https://stackoverflow.com/questions/8048556/celery-with-amazon-sqs) – Sebastian Wozny Jul 05 '23 at 07:57
  • I looked at that question before asking the question. But i didn't found the solution there. I have not any warning or error, Celery workers works without any warning. – TFA Jul 05 '23 at 08:02
  • Have you done anything in ```__init__.py``` of your project file ? – Srijan113 Jul 17 '23 at 04:44
  • Yes i added these lines to __init__.py: from .celery import app as celery_app __all__ = ('celery_app',) – TFA Jul 17 '23 at 06:20

0 Answers0