Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams django-celery-beat 1.4.0

When I run celery commands from my app directory with my venv active like celery worker -A personnel or celery beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler , it works as expected. My app's name is 'personnel'.

There are several related issues but nothing exactly like mine. Here is what happens when I try various commands.

celery worker from the project directory with venv active starts the worker and looks as the documentation shows it should (redis is working, beat works as well)

/home/www/personnel/venv/bin/python from outside of the proj dir with venv not active drops me into a shell where I can import Celery without errors

/home/www/personnel/venv/bin/celery from outside the proj shows me the celery help (usage: celery [options]...)

/home/www/personnel/venv/bin/python /home/www/personnel celery worker , which from my research is what should be working, returns: /home/www/personnel/venv/bin/python: can't find '__main__' module in '/home/www/personnel'

The above error is returned even with the -A flag.

/home/www/personnel/venv/bin/python /home/www/personnel/manage.py celery worker returns:

Unknown command: 'celery'
Type 'manage.py help' for usage.

The stdout log shows the same errors. I am guessing the command should work before supervisor comes into play.

I have started from scratch and recreated the venv with the same result.

# __init__.py
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ['celery_app']
# celery.py
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
#from celery.schedules import crontab
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'personnel.settings')
app = Celery('personnel')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
; ==================================
; celery worker config
; ==================================
[program:celery]
; full path using virtualenv
command=/home/www/personnel/venv/bin/python /home/www/personnel celery worker -A personnel -I info
directory=/home/www/personnel
;user=dunnoyet
numprocs=1
stderr_logfile=/var/log/celery.out.log
stdout_logfile=/var/log/celery.err.log
autostart=true
autorestart=true
startsecs=10
; need to wait for currently executing tasks to finish at shutdown
; increase if long running tasks
stopwaitsecs = 600
; 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
# Project structure based on django cookie cutter
pr_project
|--personnel
   |--api/
   |--...
   |--__init__.py
   |--celery.py
   |--urls.py
   |--views.py
   |--wsgi.py
|--requirements
|--...

From the project directory it works as expected but I cannot get it to work outside or start successfully with supervisor.

#personnel/settings.py
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'

As suggested I tried /home/www/personnel/venv/bin/celery worker - it starts, but looks like it cannot connect to redis

[2019-04-05 09:18:11,960: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.

With app flag /home/www/personnel/venv/bin/celery worker -A personnel:

Error:
Unable to load celery application.
The module personnel was not found.
                I don't understand the command you are trying. Why not just /home/www/personnel/venv/bin/celery worker?
– Daniel Roseman
                Apr 5, 2019 at 13:16
                Or /home/www/personnel/venv/bin/python celery worker? Basically I don't see why you have added that extra /home/www/personnel.
– Daniel Roseman
                Apr 5, 2019 at 13:23
                @DanielRoseman ha likely just because I just don't understand enough about how things work :( just trying what I have found in suggestions while googling it. I will add results as an edit up top
– Rosie
                Apr 5, 2019 at 13:28
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.