Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery No hostname was supplied. Reverting to default 'localhost'

Tags:

django

celery

I have this in my /var/log/celery/w1.log

enter image description here

I'm following the steps for Celery here.

I have this in my celery.py

from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sample.settings')

app = Celery('sample2',
            broker='amqp://',
            include=['sample2.tasks'])

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix. 
app.config_from_object('django.conf:settings', namespace='CELERY')

if __name__ == '__main__':
    app.start()

what can I do to fix this? Thanks in advance.

like image 862
Prosy Arceno Avatar asked Jun 28 '21 16:06

Prosy Arceno


1 Answers

Full document in this link.

you should just add the below line to init.py near settings.py

from .celery import app as celery_app

__all__ = ['celery_app']

project structure

- proj/
  - manage.py
  - proj/
    - __init__.py
    - settings.py
    - urls.py
like image 148
rmaleki Avatar answered Oct 28 '22 07:10

rmaleki