Celery守护进程生产无法导入Celery错误

时间:2017-01-23 11:27:53

标签: python celery celery-task celerybeat celeryd

我遵循Celery docs的所有指示。首先,我按照this link创建制作流程,这是我的应用代码。

1-test_celery / celery.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()

2-test_celery.task.py: -

from __future__ import absolute_import
from test_celery.celery 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 printTask():
    print 'Hello i am running'
    time=str(datetime.datetime.now())
    file=open('/home/hub9/myproj/data.log','ab')
    file.write(time)
    file.close()

3-:我的配置文件/ 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"

# App instance to use
# comment out this line if you don't use an app
CELERY_APP="mycelery.test_celery"
# or fully qualified:
CELERY_APP="test_celery.celery:app"

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

# 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"

**当我运行 sudo service celeryd start 我的生产工人正在启动,但我的项目给了我错误,无法导入Celery模块。我读了一些SO答案,但无法解决我的问题。 **感谢您的时间

0 个答案:

没有答案