2012-02-25 101 views
2

我不斷收到此keyError。我將字符串和id(整數)發送到任務函數,所以我不認爲這是序列化問題。並且它說keyerror在通往功能本身的道路上,而不是內容。請幫忙。爲什麼執行我的任務時,芹菜會返回KeyError?

Tasks.py

from celery.decorators import task 
from notification import models as notification 

@task(ignore_result=True) 
def notify_match_creation(match, home_team, away_team, home_team_captain, away_team_captain): 
    notification.send(User.objects.filter(profile__teams__pk__in=(home_team, away_team)), 
         "tournaments_new_match", 
         {'match': unicode(match), 
         'home_team_captain': home_team_captain, 
         'away_team_captain': away_team_captain, 
         }) 

相關設置

CELERY_RESULT_BACKEND = "database" 
CELERY_RESULT_DBURI = "postgresql://user:[email protected]/ahgl" 
BROKER_HOST = "localhost" 
BROKER_PORT = 5672 
BROKER_USER = "guest" 
BROKER_PASSWORD = "guest" 
BROKER_VHOST = "/" 

芹菜輸出:

[任務]

. apps.tournaments.tasks.notify_match_creation 
    . tournaments.tasks.notify_match_creation 
[2012-02-25 02:34:06,209: WARNING/MainProcess] [email protected] has started. 
[2012-02-25 02:34:06,477: WARNING/PoolWorker-4] E:\Webdesign\ahgl\ENV\lib\site-packages\djcelery\loaders.py:84: UserWarn 
ing: Using settings.DEBUG leads to a memory leak, never use this setting in production environments! 
    warnings.warn("Using settings.DEBUG leads to a memory leak, never " 
[2012-02-25 02:34:06,479: WARNING/PoolWorker-2] E:\Webdesign\ahgl\ENV\lib\site-packages\djcelery\loaders.py:84: UserWarn 
ing: Using settings.DEBUG leads to a memory leak, never use this setting in production environments! 
    warnings.warn("Using settings.DEBUG leads to a memory leak, never " 
[2012-02-25 02:34:06,523: WARNING/PoolWorker-3] E:\Webdesign\ahgl\ENV\lib\site-packages\djcelery\loaders.py:84: UserWarn 
ing: Using settings.DEBUG leads to a memory leak, never use this setting in production environments! 
    warnings.warn("Using settings.DEBUG leads to a memory leak, never " 
[2012-02-25 02:34:06,566: WARNING/PoolWorker-1] E:\Webdesign\ahgl\ENV\lib\site-packages\djcelery\loaders.py:84: UserWarn 
ing: Using settings.DEBUG leads to a memory leak, never use this setting in production environments! 
    warnings.warn("Using settings.DEBUG leads to a memory leak, never " 
[2012-02-25 02:34:31,520: INFO/MainProcess] Got task from broker: apps.tournaments.tasks.notify_match_creation[4dbd6258- 
5cee-49e9-8c8a-2d2105a2d52a] 
[2012-02-25 02:34:31,569: ERROR/MainProcess] Task apps.tournaments.tasks.notify_match_creation[4dbd6258-5cee-49e9-8c8a-2 
d2105a2d52a] raised exception: KeyError('apps.tournaments.tasks.notify_match_creation',) 
Traceback (most recent call last): 
    File "E:\Webdesign\ahgl\ENV\lib\site-packages\celery\concurrency\processes\pool.py", line 211, in worker 
    result = (True, func(*args, **kwds)) 
    File "E:\Webdesign\ahgl\ENV\lib\site-packages\celery\worker\job.py", line 50, in execute_and_trace 
    task = tasks[name] 
KeyError: 'apps.tournaments.tasks.notify_match_creation' 
[2012-02-25 02:38:29,773: WARNING/MainProcess] celeryd: Hitting Ctrl+C again will terminate all running tasks! 
[2012-02-25 02:38:29,773: WARNING/MainProcess] celeryd: Warm shutdown (MainProcess) 
[2012-02-25 02:38:31,779: INFO/MainProcess] process shutting down 

回答

2
+0

在我安裝的應用程序: 「比賽」, 在我的models.py調用任務: from .tasks import notify_match_creation 哪一個錯誤?我不把你的絕對路徑連接說不要... – 2012-02-26 22:57:57

+0

我應該指出,當我部署到生產(使用redis存儲),但它在本地它使用Django存儲時,它完美工作。 – 2012-02-26 23:10:11

+0

事實上,既然他們說這個問題意味着一個NotRegistered錯誤會被提出,我不認爲這是它。 – 2012-02-27 02:53:55

0

在芹菜輸出,你看到的是被拿起的任務是

tournaments.tasks.notify_match_creation (#1) 

,並在關鍵的錯誤是

KeyError: 'apps.tournaments.tasks.notify_match_creation' 

調用之前celery任務,確保它被導入時具有與拾取芹菜任務時相同的名稱(結構)(#1)。請參閱以上asksol提供的鏈接以獲取您的相關進口權。

一個可能的解決方案,當您啓動芹菜 - 嘗試

celery worker -A apps.tournaments.tasks.notify_match_creation 

這可能會調整您的任務名稱