Локальный файл конфигурации демона сельдерея без django

Я новичок в сельдерее. Я создаю проект в соответствии с инструкциями, предоставленными документами celery4.1. Ниже представлена ​​​​папка и файлы моего проекта:

 mycelery
        |
        test_celery
                  |
                   celery_app.py
                   tasks.py
                   __init__.py

1-celery_app.py

from __future__ import absolute_import
import os
from celery import Celery
from kombu import Queue, Exchange
from celery.schedules import crontab
import datetime

app = Celery('test_celery',
             broker='amqp://jimmy:jimmy123@localhost/jimmy_v_host',
             backend='rpc://',
             include=['test_celery.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
    result_expires=3600,
)

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

2-tasks.py

from __future__ import absolute_import
from test_celery.celery_app import app
import time
from kombu import Queue, Exchange
from celery.schedules import crontab
import datetime


app.conf.beat_schedule = {
    'planner_1': {
        'task': 'test_celery.tasks.printTask',
        'schedule': crontab(minute='*/1'),
    },
}


@app.task
def longtime_add(x, y):
    print 'long time task begins'
    # sleep 5 seconds
    time.sleep(5)
    print 'long time task finished'
    return x + y

@app.task
def printTask():
    print 'Hello i am running'
    time=str(datetime.datetime.now())
    file=open('/home/hub9/mycelery/data.log','ab')
    file.write(time)
    file.close()

Я скопировал файлы celeryd и celerybeat из проекта Celery github, скопировал их в /etc/init.d/ и сделал их исполняемыми. Затем я создаю файл celeryd и celerybeat в /etc/default/.

Я-/etc/по умолчанию/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"


# Where to chdir at start. path to folder containing task

CELERYD_CHDIR="/home/hub9/mycelery/test_celery/"

# 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="test_celery.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

II- /etc/default/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"


# Where to chdir at start. path to folder containing task

CELERYD_CHDIR="/home/hub9/mycelery/test_celery/"

# 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="test_celery.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

После этого я создаю пользователя и группу celery.

Вот моя проблема, я успешно запускаю этот проект, используя celery -A test_celery.celery_app worker -l info --beatcommand, но когда я запускаю свой проект, используя sudo service celeryd start ИЛИ sudo service celerybeat start

Это дает мне ошибку импорта, что нет имени модуля test_celery.celery_app.

Пожалуйста, дайте мне подсказку, что я делаю неправильно.


person Manish Yadav    schedule 24.01.2017    source источник
comment
В чем ошибка? Пожалуйста, добавьте и его.   -  person Shubham Namdeo    schedule 24.01.2017
comment
Я обновляю вопрос .... спасибо за ответ   -  person Manish Yadav    schedule 24.01.2017