Search code examples
djangogunicornpython-huey

Can't enable huey service on deploy server


I'm working in a Django project deployment. I have integrated huey to run asynchronous tasks. Locally all runs perfectly but now, at the deployment step, I'm getting troubles about huey service activation. I really can't find any information about that because I think that solution should be so simple, bat I really can't find it :(.

I'm using nginx and gunicorn services. App runs perfectly on deploy server but huey tasks are not running. I have created a huey.service file located in /etc/systemd/system/, with the following content:

[Unit]
Description=Huey Service
After=redis.service

[Service]
User=deploy
Group=www-data
WorkingDirectory=/home/deploy/projects/myproject/
ExecStart=/usr/bin/python3.6 manage.py run_huey
Restart=always

[Install]
WantedBy=multi-user.target

But I'm getting following bug:

Nov 26 21:22:15 ip-172-31-11-39 python3.6[22543]:   File "manage.py", line 17, 
in <module>
Nov 26 21:22:15 ip-172-31-11-39 python3.6[22543]:  "Couldn't import Django. 
Are you sure it's installe
Nov 26 21:22:15 ip-172-31-11-39 python3.6[22543]: ImportError: Couldn't import 
Django. Are you sure it's
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Main process exited, 
code=exited, stat
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Unit entered failed state.
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Failed with result 'exit-code'.
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Service hold-off time over, scheduling
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: Stopped Huey Service.
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Start request repeated too quickly.
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: Failed to start Huey Service.

I think that huey service is not detecting a running virtualenv, and for this reason can't find django (Because it is in a virtualenv) but I have configured previously a gunicorn service to activate it; then, I don't know how to say huey service that an active virtualenv is already running and locate it.

This is my gunicorn file config:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=deploy
Group=www-data
WorkingDirectory=/home/deploy/projects/myproject
ExecStart=/home/deploy/projects/my project/project_env/bin/gunicorn --
access-logfile - --workers 3 --bind 
unix:/home/deploy/projects/myproject/project.sock app.wsgi:application
[Install]
WantedBy=multi-user.target

How should I activate huey service on deploy server? Thank you so much.


Solution

  • Try using ExecStart=/home/deploy/projects/my project/project_env/bin/python manage.py run_huey