I have celery setup with a Django project and I can't seem to get my task to run properly. I'm using Django 1.4.3, celery 3.0.1, django-celery 3.0.17 and Python 2.7 on Ubuntu 13.04.

我在Django项目中安装了芹菜,我的任务似乎无法正常运行。我在Ubuntu 13.04上使用的是Django 1.4.3,芹菜3.0.1,Django芹菜3.0.17和Python 2.7。

I have verified my rabbitmq-server is running:

我已经验证了我的rabbitmq-server正在运行:

sudo service rabbitmq-server status
Status of node rabbit@fenster ...
[{pid,1667},
 {running_applications,[{rabbit,"RabbitMQ","3.0.2"},
                        {os_mon,"CPO  CXC 138 46","2.2.9"},
                        {mnesia,"MNESIA  CXC 138 12","4.7"},
                        {sasl,"SASL  CXC 138 11","2.2.1"},
                        {stdlib,"ERTS  CXC 138 10","1.18.1"},
                        {kernel,"ERTS  CXC 138 10","2.15.1"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:8:8] [async-threads:30] [kernel-poll:true]\n"},
 {memory,[{total,28112760},
          {connection_procs,93432},
          {queue_procs,42680},
          {plugins,0},
          {other_proc,9331824},
          {mnesia,65288},
          {mgmt_db,0},
          {msg_index,86656},
          {other_ets,764048},
          {binary,1343288},
          {code,12372068},
          {atom,512601},
          {other_system,3500875}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,6719406080},
 {disk_free_limit,1000000000},
 {disk_free,122925531136},
 {file_descriptors,[{total_limit,924},
                    {total_used,7},
                    {sockets_limit,829},
                    {sockets_used,3}]},
 {processes,[{limit,1048576},{used,151}]},
 {run_queue,0},
 {uptime,275789}]
...done.

I have my Django project setup in a virtualenv. I have celery configured in the settings.py file as:

我在一个virtualenv中设置了Django项目。我在设置中配置了芹菜。py文件:

INSTALLED_APPS = [
    # django apps

    # our apps ...

    # third party modules ...
    'djcelery',
]

import djcelery
djcelery.setup_loader()

CELERY_IMPORTS = ('my.task')

The RabbitMQ broker is setup properly - we have other celery tasks running properly.

RabbitMQ代理是正确设置的-我们有其他芹菜任务正常运行。

My task:

我的任务:

import celery

class MyClass(object):

    @celery.task()
    def my_task(self, new, old):
        # do stuff
        return

    def kick_off_tasks(self):
        # do stuff
        new = 'something'
        old = 'something else'
        self.my_task.apply_async(args(new, old), kwarg1='new', kwarg2='old)
        # do more stuff

When I run the view that calls kick_off_tasks I receive the following in the celeryd info log:

当我运行调用kick_off_tasks的视图时,我在celeryd信息日志中收到了以下内容:

./manage.py celeryd --loglevel=info

[Tasks]
  . my.task
  . other.tasks
  . more.tasks
  . etc.etc.etc

[2013-08-23 14:18:40,772: WARNING/MainProcess] celery@fenster has started.
[2013-08-23 14:20:40,757: ERROR/MainProcess] Received unregistered task of type 'my.task'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.

The full contents of the message body was:
{'retries': 0, 'task': 'my.task', 'eta': None, 'args': ('something, 'something else'), 'expires': None, 'callbacks': None, 'errbacks': None, 'kwargs': {}, 'id': 'bf4d5ee7-9701-42b6-a887-c6b6470d9810', 'utc': True} (2297b)

Traceback (most recent call last):
  File "/home/ricomoss/.virtualenvs/proton/local/lib/python2.7/site-packages/celery/worker/consumer.py", line 394, in on_task_received
    strategies[name](message, body, message.ack_log_error)
KeyError: 'my.task'

Any suggestions?

有什么建议吗?

1 个解决方案

#1


2

I was able to get this working by refactoring so that the tasks were not class methods. I placed them in our tasks.py file and everything works fine. I haven't had time to research why this is the case, which I plan to do, but until then if anyone is having the same problem you'll have a quick fix available.

我可以通过重构使其工作,这样任务就不是类方法了。我把它们放在我们的任务中。py文件,一切正常。我还没有时间去研究为什么会出现这种情况,我打算这么做,但在那之前,如果有人遇到同样的问题,你会有一个快速的解决办法。

更多相关文章

  1. 读取python中的unicode文件,该文件以与python源代码相同的方式声
  2. python 操作excel 读写同一个文件
  3. Python csv。读者:我如何返回到文件的顶部?
  4. 使用自定义qemu二进制文件与libvirt失败?
  5. 【python coding 1:网络检测】ping本地文件里的ip地址
  6. 如何输出NLTK块到文件?
  7. python 读写文本文件
  8. 批量重命名文件——python实现
  9. Django:测试成功加载静态文件

随机推荐

  1. 13、Android重写系统返回键
  2. android 常用URI 值得记住
  3. 2011年沈大海讲师Android的新浪微博客户
  4. Android AIDL机制
  5. Android尺寸标注设计大全和Android切图规
  6. Android 透明式系统栏设计
  7. 滚动条~~~xml方式(一)
  8. Android和iOS对矢量图片的支持
  9. Android学习手记:第一个应用程序!
  10. Android Dialog使用举例