0
votes

I'm new to learning celery and was following tutorials and setup my celery setup with docker I'm having issue with sending and executing celery task.

So have 4 docker container one for rabbitmq server, celery producer server and 2 worker.

Celery tasks file:

"""
CELERY MAIN FILE
"""

from celery import Celery
from time import sleep

celery_obj = Celery()
celery_obj.config_from_object('celery_config') #config file we created in same folder


@celery_obj.task
def add(num1,num2):
    print("executing add function")
    sleep(5)
    return num1 + num2

My celery config file for Producer:

"""
CELERY CONFIGURATION FILE
"""

from kombu import Exchange, Queue


broker_url = "pyamqp://rabbitmq_user:[email protected]/res_opt_rabbitmq_vhost"
result_backend = 'rpc://'
#celery_result_backend = ""
celery_imports = ('res_opt_code.tasks')

task_queues = (
    Queue('worker_A_kombu_queue',Exchange('celery',type='direct'),routing_key='worker_A_rabbitmq_queue'),
    Queue('worker_B_kombu_queue',Exchange('celery',type='direct'),routing_key='worker_B_rabbitmq_queue')
)

Config file for worker_A:

"""
CELERY CONFIGURATION FILE
"""

from kombu import Exchange, Queue


broker_url = "pyamqp://rabbitmq_user:[email protected]/res_opt_rabbitmq_vhost"
result_backend = 'rpc://'
#celery_result_backend = ""
celery_imports = ('worker_code.tasks')

task_queues = (
    Queue('worker_A_kombu_queue',Exchange('celery',type='direct'),routing_key='worker_A_rabbitmq_queue'),
    Queue('worker_B_kombu_queue',Exchange('celery',type='direct'),routing_key='worker_B_rabbitmq_queue')
)

Command for starting celery on producer:

celery -A tasks worker --loglevel=DEBUG -f log_file.txt

command for starting celery on worker:

celery -A tasks worker -n celery_worker_A -Q worker_A_kombu_queue --loglevel=DEBUG

Function call from producer:

from tasks import add
add.apply_async([4,4],routing_key='worker_A_rabbitmq_queue')

#also tried local executing the function but not logs of functions it's in pending

add.delay(4,4) 

could you guyz please help me what I'm doing wrong here In Logs I'm able to see worker_A connected but no logs for function