2016-08-13 4 views
0

Ich habe Schwierigkeiten zu verstehen, wie Sellerie nach dem Einrichten einiger geplante Aufgaben ausgeführt wird.Unsicher, wie Sellerie unter Windows für regelmäßige Aufgaben ausgeführt wird

Zunächst wird mein Projektverzeichnis wie folgt strukturiert:

enter image description here

blogpodapi\api\__init__.py enthält

from tasks import app 
import celeryconfig 

blogpodapi\api\celeryconfig.py enthält

from datetime import timedelta 

# Celery settings 
CELERY_BROKER_URL = 'redis://localhost:6379/0' 
BROKER_URL = 'redis://localhost:6379/0' 
CELERY_RESULT_BACKEND = 'redis://localhost:6379/1' 
CELERY_ACCEPT_CONTENT = ['application/json'] 
CELERY_TASK_SERIALIZER = 'json' 
CELERY_RESULT_SERIALIZER = 'json' 
CELERY_TIMEZONE = 'UTC' 
CELERY_IMPORTS = ("api.tasks",) 

CELERYBEAT_SCHEDULE = { 
    'write-test': { 
     'task': 'api.tasks.addrandom', 
     'schedule': timedelta(seconds=2), 
     'args': (16000, 42) 
    }, 
} 

blogpodapi\api\tasks.py enthält

from __future__ import absolute_import 
import random 
from celery import Celery 
app = Celery('blogpodapi') 


@app.task 
def add(x, y): 
    r = x + y 
    print "task arguments: {x}, {y}".format(x=x, y=y) 
    print "task result: {r}".format(r=r) 
    return r 


@app.task 
def addrandom(x, *args): # *args are not used, just there to be interchangable with add(x, y) 
    y = random.randint(1,100) 
    print "passing to add(x, y)" 
    return add(x, y) 

blogpodapi\blogpodapi\__init__.py enthält

from __future__ import absolute_import 

# This will make sure the app is always imported when 
# Django starts so that shared_task will use this app. 
from .celery import app as celery_app # noqa 

blogpodapi\blogpodapi\settings.py

... 

# Celery settings 
CELERY_BROKER_URL = 'redis://localhost:6379/0' 
BROKER_URL = 'redis://localhost:6379/0' 
CELERY_RESULT_BACKEND = 'redis://localhost:6379/1' 
CELERY_ACCEPT_CONTENT = ['application/json'] 
CELERY_TASK_SERIALIZER = 'json' 
CELERY_RESULT_SERIALIZER = 'json' 
CELERY_TIMEZONE = 'UTC' 
CELERY_IMPORTS = ("api.tasks",) 

... 
enthält dann celery -A blogpodapi beat in Eingabeaufforderung ausführen und die folgende bekommen

D:\blogpodapi>celery -A blogpodapi worker --loglevel=info 

-------------- [email protected] v3.1.23 (Cipater) 
---- **** ----- 
--- * *** * -- Windows-8-6.2.9200 
-- * - **** --- 
- ** ---------- [config] 
- ** ---------- .> app:   blogpodapi:0x348a940 
- ** ---------- .> transport: redis://localhost:6379/0 
- ** ---------- .> results:  redis://localhost:6379/1 
- *** --- * --- .> concurrency: 2 (prefork) 
-- ******* ---- 
--- ***** ----- [queues] 
-------------- .> celery   exchange=celery(direct) key=celery 


[tasks] 
    . api.tasks.add 
    . api.tasks.addrandom 
    . blogpodapi.celery.debug_task 

[2016-08-13 13:01:51,108: INFO/MainProcess] Connected to redis://localhost:6379/0 
[2016-08-13 13:01:52,122: INFO/MainProcess] mingle: searching for neighbors 
[2016-08-13 13:01:55,138: INFO/MainProcess] mingle: all alone 
c:\python27\lib\site-packages\celery\fixups\django.py:265: UserWarning: 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 ' 

[2016-08-13 13:02:00,157: WARNING/MainProcess] c:\python27\lib\site-packages\celery\fixups\django.py:265: UserWarning: 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 ' 

[2016-08-13 13:02:27,790: WARNING/MainProcess] [email protected] ready. 

I:

D:\blogpodapi>celery -A blogpodapi beat 
celery beat v3.1.23 (Cipater) is starting. 
__ - ... __ -  _ 
Configuration -> 
    . broker -> redis://localhost:6379/0 
    . loader -> celery.loaders.app.AppLoader 
    . scheduler -> celery.beat.PersistentScheduler 
    . db -> celerybeat-schedule 
    . logfile -> [stderr]@%INFO 
    . maxinterval -> now (0s) 
[2016-08-13 13:02:51,937: INFO/MainProcess] beat: Starting... 

Aus irgendeinem Grund kann ich nicht zu sehen scheinen 10

ich celery -A blogpodapi worker --loglevel=info in Eingabeaufforderung ausführen und die folgende erhalten Meine regelmäßigen Aufgaben werden protokolliert. Was mache ich falsch?

UPDATE: hier ist mein celery.py ...

from __future__ import absolute_import 
import os 
from celery import Celery 

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

from django.conf import settings # noqa 

app = Celery('blogpodapi') 

# 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)) 
+0

laufen Was genau in Ihrer 'celery.py ist '? Sie haben den Inhalt aller anderen Dateien außer "sellery.py" –

+0

ich muss vergessen haben. Habe gerade die Frage aktualisiert! – methuselah

Antwort

2

Sie benötigen Sellerie schlagen mit der Sellerie-Einstellungsdatei

celery -A blogpodapi.celery beat --loglevel=INFO 
+0

Wie machen Sie das – methuselah

+0

ist anstelle von '' 'sellerie -A blogpodapi Beat''' führen Sie den Befehl über –

+0

Kann ich nur das oder muss ich noch etwas tun? – methuselah

Verwandte Themen