Report this

What is the reason for this report?

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

Posted on February 14, 2024

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

[program:celery_beat]
command=/myprojects/projectenv/bin/celery -A core beat -l info
directory=/myprojects/green_bill
user=root
autostart=true
autorestart=true
stderr_logfile=/var/log/celery_beat.err.log
stdout_logfile=/var/log/celery_beat.out.log
environment=PATH="/myprojects/projectenv/bin:%(ENV_PATH)s"

the below is celery_worker.conf file

[program:celery_worker]
command=/myprojects/projectenv/bin/celery -A core.celery worker --pool=solo -l info
directory=/myprojects/green_bill
user=root
autostart=true
autorestart=true
stderr_logfile=/var/log/celery_worker.err.log
stdout_logfile=/var/log/celery_worker.out.log
environment=PATH="/myprojects/projectenv/bin:%(ENV_PATH)s"


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!

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.

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.