Source

django-celery-about / source / djkombu.rst

What the pygmy did ? : kombu.transport.django(djkombu)

admin.pyでDjkombuを確認

vi admin.py

# -*- coding: utf-8 -*-
from django.contrib import admin
from django.conf import settings

if settings.DEBUG:
    try:
        # from djkombu.models import Queue as KombuQueue,Message as KombuMessage
        from kombu.transport.django.models import Queue as KombuQueue,Message as KombuMessage
        from djcelery.models import TaskMeta,TaskSetMeta

        ### KombuQueue
        class KombuQueueAdmin(admin.ModelAdmin):
            list_display=tuple([f.name for f in KombuQueue._meta.fields ])
        admin.site.register(KombuQueue,KombuQueueAdmin)

        ### KombuMessage
        class KombuMessageAdmin(admin.ModelAdmin):
            list_display=tuple([f.name for f in KombuMessage._meta.fields])
        admin.site.register(KombuMessage,KombuMessageAdmin)

        ### TaskMeta
        class TaskMetaAdmin(admin.ModelAdmin):
            list_display=tuple([f.name for f in TaskMeta._meta.fields])
            list_filter = ('status',)
            date_hierarchy = 'date_done'
        admin.site.register(TaskMeta,TaskMetaAdmin)

        ### TaskSetMeta
        class TaskSetMetaAdmin(admin.ModelAdmin):
            list_display=tuple([f.name for f in TaskSetMeta._meta.fields])
        admin.site.register(TaskSetMeta,TaskSetMetaAdmin)

    except Exception,e:
        print e
        pass

何が起きているか?

ワーカーが起動した時にキューを追加

pidbox : Workerのリモートコントロールコマンド用のキュー

Queue

ワーカーがMessageからレコード取り出しメッセージ復元

>>> body="gAJ9cQEoVQdyZXRyaWVzcQJLAFUEdGFza3EDVQ9hcHAudGFza3MuaGVsbG9xBFUIZXJyYmFja3NxBU5VCWNhbGxiYWNrc3EGTlUGa3dhcmdzcQd9cQhVA2V0YXEJTlUEYXJnc3EKVQd0b28gaG90cQuFcQxVAmlkcQ1VJGE0NjVjNzdlLTJkYTgtNGJlNC05OWI5LTMzZGFhYTJjYjljZHEOVQdleHBpcmVzcQ9OVQN1dGNxEIh1Lg=="
>>> import base64
>>> import pickle
>>> pickle.loads( base64.b64decode(body) )
{
    'retries': 0,
    'task': 'app.tasks.hello',
    'eta': None,
    'args': ('too hot',),
    'kwargs': {},
    'expires': None,
    'callbacks': None,
    'errbacks': None,
    'id': 'a465c77e-2da8-4be4-99b9-33daaa2cb9cd',
    'utc': True
}

ワーカーがTaskMetaをSUCCESS更新

AsyncResult = TaksMeta モデル( task states )