Celery Queue似乎没有注册我的任务

时间:2010-10-19 21:58:08

标签: django rabbitmq celery

我正在使用Django和Celery与RabbitMQ进行通信。我已经注册了所有任务,并将它们放在我的设置文件中的CELERY_IMPORTS元组中。当我运行任务时,我收到“未注册”错误消息。

# tail -f /var/log/celeryd.log 
    . logfile -> /var/log/celeryd.log@INFO
    . events -> OFF
    . beat -> OFF
    . tasks ->
    . apps.contact.tasks.emailContact
    . apps.declaration.tasks.MailChimpSignup
    . apps.questions.tasks.emailQuestionTask
    . queued_storage.tasks.SaveToRemoteTask
[2010-10-19 17:53:44,958: INFO/PoolWorker-1] child process calling self.run()
[2010-10-19 17:53:44,971: WARNING/MainProcess] celery@nolabels.org has started.


[2010-10-19 17:54:03,962: ERROR/MainProcess] Unknown task ignored: "Task of kind 'apps.declaration.tasks.MailChimpSignup' is not registered, please make sure it's imported.": {'retries': 0, 'task': 'apps.declaration.tasks.MailChimpSignup', 'args': [], 'eta': None, 'kwargs': {'email': u'abc123@asdfd.com'}, 'id': '919c6030-70b1-43e6-87f5-907fa0f52c08'}

下面是我的任务定义:

class MailChimpSignup(Task):
    def run(self, email, **kwargs):
        """
        This will register the declaration signer on mail chimp.
        """
        logger = self.get_logger(**kwargs)
        logger.info("Processed mailchimp signup for %s" % email)
        chimp = chimpy.Connection(settings.MAILCHIMP_API_KEY)

        try:
            chimp.list_member_info(settings.MAILCHIMP_LIST_ID, email)
        except ChimpyException:
            try:
                x = chimp.list_subscribe(
                        settings.MAILCHIMP_LIST_ID,
                        email,
                        {
                        #    'FNAME': self.first_name,
                        #    'LNAME': self.last_name,
                        },
                        email_type='HTML',
                        double_optin = False,
                )
            except ChimpyException:
                return False
        return True
tasks.register(MailChimpSignup)

1 个答案:

答案 0 :(得分:2)

奇怪。它似乎有正确的名称。

您可以尝试手动为任务分配名称吗?

@task(name="MailChimpSignup")
def ...