The tasks defined in the proj/proj/celery.py file directly are registering successfully.
However, shared tasks defined in the custom django apps are not registering to the database and not showing up in admin at /admin/django_celery_beat/periodictask/.
proj/proj/celery.py
# .. imports.. #
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
celery_app = Celery('proj')
celery_app.config_from_object('django.conf:settings', namespace='CELERY')
celery_app.autodiscover_tasks()
@celery_app.task(bind=True)
def hello():
print "This task is registering successfully"
proj/app/tasks.py
from celery import shared_task
@shared_task
def app_hello():
print "This task is not registering"
I think, this could be because of the celery autodiscover_tasks not working as intended.
Sorry, this issue has nothing to do with django-celery-beat. Just for anyone's reference who hits this issue page in future, I'll describe what solved the issue for me. I had not replaced django.conf:settings in the celery.py file with the django settings variable.
In proj/proj/celery.py, this line:
celery_app.config_from_object('django.conf:settings', namespace='CELERY')
Should be,
celery_app.config_from_object(settings, namespace='CELERY')
Don't forget thefrom django.conf import settings at the top of the file.
celery_app.config_from_object(settings, namespace='CELERY')
Don't forget thefrom django.conf import settings at the top of the file.
This does not work for me
I agree, this issue has nothing to do with django-celery-beat as I am experiencing the same issue, but have not been able to find a solution anywhere. The bound task in celery.py is found, but the shared tasks in any appname/tasks.py files are not found.
@pramttl - the solution you suggested does not work for me either.
@tsantor try to add on your proj/proj/__init__.py
from .celery import celery_app
@dagnaldo thanks , it works
@dagnaldo and his answer should be in the quick start guide. Been using celery for a year and never had to reach for this solution before.
@tsantor try to add on your
proj/proj/__init__.pyfrom .celery import celery_app
It is imported as said in the quick start guide, but still shared_task is not showing up.
Though importing django.conf.settings fixed recurrsion error.
from django.conf import settings
app.config_from_object(settings)
It's working for me and able to see shared_task
@tsantor try to add on your
proj/proj/__init__.pyfrom .celery import celery_app
it works, thanks a lot
Most helpful comment
@tsantor try to add on your
proj/proj/__init__.py