Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery task method is not getting called

I have the following method call & particular method in a Python Django web application. (Please note that I am not that much familiar with python, Django or celery)

Method as follows :

@shared_task(bind=True, default_retry_delay=10, max_retries=3, ignore_results=False)
def push_sns_message(self, sns_alias, message, target_arn):
    """
    Celery task
    """
    logger.debug("########## Hit the Celery Task ###############")
    print "########## Hit the celery ###########"
    connection = sns_connections[sns_alias]
    return connection.publish(message=message, target_arn=target_arn) 

Method Call as follows:

print "########## Calling to celery ###########"
push_sns_message.s(self.sns_connection, json.dumps(wrapper[0]), self.sns_arn)

The issue is whenever I run application, it comes to push_sns_message.s() but doesn't go inside it. I can see the print

"########## Calling to celery ###########"

but cannot see following print and also other lines also are not called

"########## Hit the celery ###########"

Please explain this behavior.

like image 850
Udara Seneviratne Avatar asked May 07 '26 10:05

Udara Seneviratne


1 Answers

I have a few potential suggestions in the case that the other answer does not help.

First, do you have the celery worker running? If not, the task will be queued up, but not executed until the worker is ready to receive the task. You can simply call the function (without the .s) and the function should execute as a regular function.

Second, the ".s" is a signature, but is not actually called without "apply_async". Try called the function like this:

push_sns_message.s(self.sns_connection, json.dumps(wrapper[0]), self.sns_arn).apply_async()

or like this:

push_sns_message.s(self.sns_connection, json.dumps(wrapper[0]), self.sns_arn).delay()

Hopefully this will help, but here's the documentation that you would need to further investigate the issue.

like image 118
CoolestNerdIII Avatar answered May 08 '26 22:05

CoolestNerdIII



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!