After adding SSL to my project, Celery is not functioning properly

After initially implementing Celery in my project, it was working fine. However, after adding SSL to the project, Celery has stopped functioning, and emails are not being sent.The other functionalities in my project are sending emails successfully, but the emails triggered by Celery tasks are not being sent.

the below is the output that means celery running in background properly.

root@django-project:/myprojects# source projectenv/bin/activate
(projectenv) root@django-project:/myprojects# cd ..
(projectenv) root@django-project:/# sudo supervisorctl stop celery_worker
celery_worker: stopped
(projectenv) root@django-project:/# sudo supervisorctl stop celery_beat
celery_beat: stopped
(projectenv) root@django-project:/# sudo supervisorctl restart celery_worker
celery_worker: ERROR (not running)
celery_worker: started
(projectenv) root@django-project:/# sudo supervisorctl restart celery_beat
celery_beat: ERROR (not running)
celery_beat: started
(projectenv) root@django-project:/# sudo supervisorctl status celery_worker
celery_worker                    RUNNING   pid 353104, uptime 0:00:27
(projectenv) root@django-project:/# sudo supervisorctl status celery_beat
celery_beat                      RUNNING   pid 353113, uptime 0:00:25
(projectenv) root@django-project:/#

the below is celery_beat.conf file

command=/myprojects/projectenv/bin/celery -A core beat -l info

the below is celery_worker.conf file

command=/myprojects/projectenv/bin/celery -A core.celery worker --pool=solo -l info

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
February 14, 2024

Heya @rashmijoshi,

It’s hard to pinpoint the exact reason like that so here are some steps you can try to further troubleshoot the issue.

1. Check Celery Configuration

  • Broker URL: If you’re using a message broker like RabbitMQ or Redis, ensure that its connection string (broker URL) in your Celery configuration reflects the SSL settings.
  • Email Backend: Make sure that your email backend configuration in Django is correctly set up for SSL. This includes the correct port (usually 465 for SMTPS or 587 for STARTTLS), use of SSL/TLS (EMAIL_USE_TLS or EMAIL_USE_SSL), and valid SMTP server credentials.

2. Review Logs

  • Celery Logs: Check the Celery worker and beat logs (/var/log/celery_worker.err.log and /var/log/celery_beat.err.log) for any errors or warnings that occurred during the task execution, especially those related to email sending or SSL issues.
  • Email Server Logs: If possible, review the logs of your email server. They might provide clues if the connection attempts are being rejected or if there are SSL handshake issues.

3. Examine Network Configuration

  • Firewall Settings: Ensure that your server’s firewall isn’t blocking outgoing connections on the ports used by your email server.
  • Network Changes: If there were any network changes when implementing SSL (like changes in DNS, IP addresses, or network routes), ensure they aren’t affecting Celery’s ability to reach the email server.

4. Test Email Functionality Independently

  • Separate Script Test: Write a small Python script that sends an email using the same settings and environment as your Django project. Run this script in the same environment where Celery runs to see if the issue is isolated to Celery or is more general.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel