Joey Fran
Joey Fran

Reputation: 627

Celery asynchronous in django does not work

I am trying to create an asynchronous task using celery, but I am not achieving success.

I have a task that sends emails:

@shared_task()
def send_email_example(email_id):
     ...

I call it using the delay() method:

class SomeModelExample:
    ...
    
    def example(self):
        ...
        send_email_example.delay(self.id)

Locally, I run the celery and can use it. However, in my server, when I use the method that calls the function it takes more than 30 seconds and I receive a status code 502.

I hope that my celery setup is ok, because my periodc tasks works.

Solution

Testing it myself I saw that the celery is really ok. The problem was with my tests on the server.

Upvotes: 0

Views: 236

Answers (1)

Andrey Borzenko
Andrey Borzenko

Reputation: 738

At this stage I would try:

  1. Use decorator without brackets: @shared_task
  2. Increase harakiri time to >60 seconds on your server to see if it is a task problem or a server problem.

Upvotes: 1

Related Questions