Celery daemon production celeryd and celerybeat error

78 views
Skip to first unread message

mya...@hub9.io

unread,
Jan 25, 2017, 5:24:54 AM1/25/17
to celery-users
I am newbie to Celery. I had created a project :

proj--->celery_app.py, tasks.py, celeryconfig.py

My file contains:-

1-celeryconfig.py

 # config file for Celery Daemon 
from __future__ import absolute_import 
from celery.schedules import crontab 
# from proj import tasks 
import proj 
CELERY_IMPORTS = ('proj.tasks', ) 
# default RabbitMQ broker 
BROKER_URL = 'amqp://' 
# default RabbitMQ backend 
CELERY_RESULT_BACKEND = 'amqp://' 
# TimeZone, this should be changed 
CELERY_TIMEZONE = 'Asia/Kolkata' 
CELERY_TASK_RESULT_EXPIRES = 300 #time in seconds. 
CELERYBEAT_SCHEDULE = {'every-minute' :
                                    {'task': 'proj.tasks.add',
                                        'schedule': crontab(minute='*'),
                                        'args': (1,2),
                                    },
                        }




2- celery_app.py

from __future__ import absolute_import
from celery import Celery

app=Celery(include=['proj.tasks'])

app.config_from_object('proj.celeryconfig')

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



3.tasks.py

from __future__ import absolute_import
from proj.celery_app import app

@app.task(bind=True)
def add(x,y):
    print x+y
    return x+y

@app.task()
def mul(x,y):
    print x*y
    return x*y

@app.task()
def xsum(numbers):
    return sum(numbers)

My above project is working fine when i am starting worker by command :
 celery -A proj worker --loglevel=info --beat
Its work fine.

After that i copied celeryd and celeybeat from celery github project into init.d.

And i had created ceteryd and celerybeat in my /etc/default/celeryd and /etc/default/celerybeat and my files contains :

celeryd:-

# Names of nodes to start
#   most will only start one node:
#CELERYD_NODES="worker1"
#   but you can also start multiple and configure settings
#   for each in CELERYD_OPTS (see `celery multi --help` for examples).
CELERYD_NODES="worker1 worker2 worker3"

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"


#CELERYD_HOME="/home/hub9/proj"

# Where to chdir at start. path to folder containing task
CELERYD_CHDIR="/home/hub9/proj"

# App instance to use
# comment out this line if you don't use an app
#CELERY_APP = "file/locatin/of/app"
# or fully qualified:
CELERY_APP="celery_app:app"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=3000 --concurrency=3 --config=celeryconfig"

# %N will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%N.log"
CELERYD_PID_FILE="/var/run/celery/%N.pid"

# Workers should run as an unprivileged user.
#   You need to create this user manually (or you can choose
#   a user/group combination that already exists, e.g. nobody).
CELERYD_USER="celery"
CELERYD_GROUP="celery"

# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1


celerybeat:-

# Names of nodes to start
#   most will only start one node:
#CELERYD_NODES="worker1"
#   but you can also start multiple and configure settings
#   for each in CELERYD_OPTS (see `celery multi --help` for examples).
CELERYD_NODES="worker1 worker2 worker3"

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"


#CELERYD_HOME="/home/hub9/proj"

# Where to chdir at start. path to folder containing task
CELERYD_CHDIR="/home/hub9/proj"

# App instance to use
# comment out this line if you don't use an app
#CELERY_APP = "file/locatin/of/app"
# or fully qualified:
CELERY_APP="celery_app:app"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=3000 --concurrency=3 --config=celeryconfig"

# %N will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%N.log"
CELERYD_PID_FILE="/var/run/celery/%N.pid"

# Workers should run as an unprivileged user.
#   You need to create this user manually (or you can choose
#   a user/group combination that already exists, e.g. nobody).
CELERYD_USER="celery"
CELERYD_GROUP="celery"

# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1

After that when i start using sudo service celeryd start it give me error that:
ImportError: No module named proj

And when i run using sudo service celerybeat start it give me error:
ImportError: No module named proj

Please suggest me what to do .
Thanks for your time.

Reply all
Reply to author
Forward
0 new messages