celery守护进程生产没有django的本地配置文件

时间:2017-01-24 06:41:52

标签: python-2.7 celery celery-task celerybeat celeryd

我是芹菜的新手。我根据celery4.1 docs提供的指令创建了一个项目.Below是我的项目文件夹和文件:

 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()

我从Celery github项目复制了celeryd和celerybeat文件并复制到/etc/init.d/并使它们成为可执行文件。然后我创建celeryd和celerybeat文件到/ etc / default /.

I- / etc / default / 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 -A test_celery.celery_app worker -l info --beat命令成功运行此项目但是当我使用sudo service celeryd start OR sudo service celerybeat start

启动项目时

它给我导入错误,没有模块名称test_celery.celery_app。

请告诉我一些我做错了什么。

0 个答案:

没有答案
相关问题