DEV Community

Deploying Django with Celery and Redis on Ubuntu

Idris Rampurawala on November 05, 2019

Most of the time we sort of think about project deployment difficulties before even implementing the project itself. My aim in writing this post is...
Collapse
 
oscjara profile image
oscjara

thanks so much for the article, very useful and easy to follow. I did all the procedures but still getting un error on the worker log:

[2021-12-29 18:37:21,110: ERROR/MainProcess] consumer: Cannot connect to redis://redis:6379/0: Error -3 connecting to redis:6379. Temporary failure in name resolution..

how can I fix this error?

thanks in advance.

OJ

Collapse
 
idrisrampurawala profile image
Idris Rampurawala

Hey, thanks for reading through, glad you liked it.
For this error, you could check the following:

  • Is your redis server working on mentioned host and port?
  • Are you able to connect to it via cli?
  • Is there any firewall settings that is refusing your connection?

This issue is purely based on your redis configuration. Please check the respective documentations for the resolution :)

Collapse
 
oscjara profile image
oscjara

Hey Idris, well... my bad, I skipped the step ## since I had already redis on my app but after reading again carefully I realized I needed to install redis-server :).

All the services are running "sudo supervisorctl status all" but I am not getting the email. How can I double check redis is running the task? which documentations can I read?

Thread Thread
 
idrisrampurawala profile image
Idris Rampurawala

Hey, great that you were able to make if work! 👏

The testing of your code is fully dependent on your implementation. However, I can recommend you to monitor the celery logs for background tasks and also can refer to its documentation.

Collapse
 
peterpalace profile image
disgra

Thank you for this article!
For me, there was an error ([ERROR] Invalid address) regarding the command:
gunicorn Myproj.wsgi:application --bind 8001
I needed to add ":" before the port:
gunicorn Myproj.wsgi:application --bind :8001
Thank you for sharing.

Collapse
 
idrisrampurawala profile image
Idris Rampurawala

That's strange! Because it didn't require at my side and as per the documentation it is not required.
Good that you were able to figure it out and got your script working! 🎉 🙂

Collapse
 
databrown profile image
DataBrown

Hi Idris, I'm getting a spawn Error on the supervisor start my_project (gunicorn.conf) and I can't figure out why.

The start_gunicorn.bash works fine on its own but can't seem to boot under supervisor.

Collapse
 
idrisrampurawala profile image
Idris Rampurawala

Hi,
Could you please attach the screenshot of the error here? It will help me in diagnosis.

Secondly, please also check the following:

  • The supervisor configuration is correctly configured as per your project paths
  • Make sure the gunicorn.bash file has been given execution writes.
Collapse
 
wisnercelucus profile image
wisnercelucus

Thank you for this article. I have read it because I was interested in the Celery part.

My application is running on DigitalOcean (ubuntu 22.X.X). I was able to follow all the steps to configure gunicorn and the domains and nginx. But my application has some long tasks that needs Celery and redis. It worked fine on heroku but i moved it to DigitalOcean.

I need a way to automate the Celery command and your article seems to be good.
This: sudo supervisorctl start all seems to work.
but this: "sudo supervisorctl status all" gives me an error:
celery FATAL Exited too quickly (process log may have details)

The log file is empty though. bellow is my conf file following yours.

; ==================================
; celery worker supervisor
; ==================================

[program:celery]
directory=/home/smartly/projects/smartlysms
command=/home/smartly/projects/smartlysms/venv/bin/celery worker -A app.celery --loglevel=INFO

user=smartly
numprocs=1
stdout_logfile=/home/smartly/projects/logs/celery/worker-access.log
stderr_logfile=/home/smartly/projects/logs/celery/worker-error.log
stdout_logfile_maxbytes=50
stderr_logfile_maxbytes=50
stdout_logfile_backups=10
stderr_logfile_backups=10
autostart=true
autorestart=true
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; Causes supervisor to send the termination signal (SIGTERM) to the whole process group.
stopasgroup=true

; Set Celery priority higher than default (999)
; so, if rabbitmq is supervised, it will start first.
priority=1000

Collapse
 
muhamedoufi profile image
Muhamedou Fi

Please the same example but using apache server 🙏