Yoseph_Reyes
Yoseph_Reyes

Reputation: 21

Celery/Redis trigger send_email task twice per task

I have a Celery task to send an email, but since some time ago this email arrives 2 times with the same subject and body. I consider important to mention, for sending emails I use SendGrid. Attached is a fragment of the code used to run the task

app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.broker_transport_options = {'visibility_timeout': 43200}

"send_sales_ga_rental":{
    "task": "core.tasks.send_sales_ga_rental",
    'schedule': crontab(0, hour=12, day_of_week='1')        
}

app.autodiscover_tasks()

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

Finally, I consider important to mention that this application runs on a Heroku server.

[![enter image description here][1]][1] [1]: https://i.sstatic.net/K6cAoCGy.png

Upvotes: 0

Views: 44

Answers (1)

Mahammed Imdad K
Mahammed Imdad K

Reputation: 1

With the visibility_timeout set to 43200 (12 hours), it's possible that the task is being executed twice due to a duplicated task being created. You can try reducing the visibility_timeout to a lower value (e.g., 3600 for 1 hour) to see if the issue persists. Enable Celery's built-in logging by setting CELERYD_LOG_FORMAT and CELERYD_LOG_FILE in your Django settings.

@app.task(bind=True)

def debug_task(self):

print(f'Request: {self.request!r}')

logger.info(f'T

Upvotes: 0

Related Questions