[Python] Using Celery with Amazon SQS, messages are waiting in 'Messages Avaliable'

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    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:

    [​IMG]

    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

    Continue reading...

Compartilhe esta Página