SchedulingError:无法应用计划任务下载程序:参数必须是int,或者具有fileno()方法

时间:2014-05-11 08:15:06

标签: redis celery django-celery supervisor

我已将djcelery和kombu.transport.django添加到django应用程序中。

settings.py:

import djcelery
djcelery.setup_loader()

from .celery import app as celery_app

BROKER_URL = "redis://abc:abc@localhost:6379/0"
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
CELERY_TIMEZONE = "Europe/London"
CELERY_ENABLE_UTC = True

# store AsyncResult in redis
CELERY_RESULT_BACKEND = "redis"
REDIS_HOST = "localhost"
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_VHOST = 0 
REDIS_USER="xyz"
REDIS_PASSWORD="xyz"
REDIS_CONNECT_RETRY = True

celery.py

from __future__ import absolute_import

import os

from celery import Celery

from django.conf import settings

from . import celeryconfig

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

app = Celery('apps')   

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

芹菜主管配置:

[program:celeryd]

command=/home/vagrant/.virtualenvs/project/bin/python /vagrant/project/manage.py celeryd -B -E -c 1  --settings=config.settings

directory=/vagrant/project

user=vagrant

autostart=true
autorestart=true

stdout_logfile=/var/log/supervisor/celeryd.log
stderr_logfile=/var/log/supervisor/celeryd_err.log

当使用django-celery接口安排任务时,该接口应该下载一些文件,抛出以下错误:

Traceback (most recent call last):

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/celery/beat.py", line 203, in maybe_due
    result = self.apply_async(entry, publisher=publisher)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/celery/beat.py", line 259, in apply_async
    entry, exc=exc)), sys.exc_info()[2])

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/celery/beat.py", line 251, in apply_async
    **entry.options)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/celery/app/task.py", line 555, in apply_async
    **dict(self._get_exec_options(), **options)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/celery/app/base.py", line 323, in send_task
    reply_to=reply_to or self.oid, **options

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/celery/app/amqp.py", line 302, in publish_task
    **kwargs

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/messaging.py", line 168, in publish
    routing_key, mandatory, immediate, exchange, declare)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/connection.py", line 440, in _ensured
    return fun(*args, **kwargs)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/messaging.py", line 180, in _publish
    [maybe_declare(entity) for entity in declare]

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/messaging.py", line 111, in maybe_declare
    return maybe_declare(entity, self.channel, retry, **retry_policy)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/common.py", line 99, in maybe_declare
    return _maybe_declare(entity)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/common.py", line 110, in _maybe_declare
    entity.declare()

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/entity.py", line 505, in declare
    self.queue_declare(nowait, passive=False)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/entity.py", line 531, in queue_declare
    nowait=nowait)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/transport/virtual/__init__.py", line 447, in queue_declare
    return queue_declare_ok_t(queue, self._size(queue), 0)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/transport/redis.py", line 651, in _size
    sizes = cmds.execute()

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/redis/client.py", line 2157, in execute
    conn.disconnect()

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/transport/redis.py", line 800, in disconnect
    channel._on_connection_disconnect(self)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/transport/redis.py", line 461, in _on_connection_disconnect
    self.connection.cycle._on_connection_disconnect(connection)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/transport/redis.py", line 259, in _on_connection_disconnect
    self.poller.unregister(connection._sock)

File "/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/utils/eventio.py", line 85, in unregister
    self._epoll.unregister(fd)

SchedulingError: Couldn't apply scheduled task downloader: argument must be an int, or have a fileno() method.

并且我没有得到任何线索来自这些错误......

任何建议都将不胜感激。

更新1:

我使用django-celery管理界面来安排任务,并在INSTALLED_APP中注册的应用程序中定义任务,如下所示:

@shared_task
def downloader():
    # execute static/shell_scripts/feed_downloader.sh
    import subprocess
    PROJECT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    subprocess.call(PROJECT_PATH+"/static/shell_scripts/feed_downloader.sh", shell=True)

feed_downloader.sh文件调用django管理命令,如果我执行独立的工作正常如下:

python manage.py feed_downloader

如果我在行号之前添加一个print语句。 85检查文件中的fd参数

/home/vagrant/.virtualenvs/project/local/lib/python2.7/site-packages/kombu/utils/eventio.py

然后打印以下消息:

see this <socket._socketobject object at 0x131b750>
see this None
see this <socket._socketobject object at 0x131bc90>
see this None

0 个答案:

没有答案