2017-10-26 15 views
0

Ich fand ein Beispiel für den Betrieb von Sellerie mit Mongodb als Back-End-Ergebnis hier original code example. In seinem Beispiel hat er CELERYBEAT_SCHEDULE mit einigen Parametern, die jede Minute ausgeführt werden, in meinem Fall habe ich diesen Code gerade auskommentiert. In meinem Fall möchte ich die Aufgabe nur ausführen, sobald sie empfangen wird. Aus dem Arbeitsprotokoll sehe ich nicht einmal, dass die Aufgabe empfangen wird, und die Ausgabe für result.status ist PENDING. Warum bleibt das im ausstehenden Status und schließt die Aufgabe nicht ab? Es ist eine einfache Addition Aufgabe, so dass ich es nicht lange dauern könnte.Sellerie-Status im Status "Ausstehend"

Eine andere Sache ist, ich virtuellen Umgebung haben so von dem, was gesagt wurde, ist zu mir, ich sollte Sellerie als solche „Sellerie Multi Start Arbeiter --loglevel = info

Ich bin neu in Sellerie laufen und diese ist etwas verwirrend für mich. Vielen Dank im Voraus für jede Hilfe.

celeryconfig.py Datei

# from celery.schedules import crontab 

CELERY_RESULT_BACKEND = "mongodb" 
CELERY_MONGODB_BACKEND_SETTINGS = { 
    "host": "127.0.0.1", 
    "port": 27017, 
    "database": "jobs", 
    "taskmeta_collection": "stock_taskmeta_collection", 
} 

# this was part of the original code but i commented out in hopes 
# it would run the task right away and not delay. 
# 
#used to schedule tasks periodically and passing optional arguments 
#Can be very useful. Celery does not seem to support scheduled task but only periodic 
# CELERYBEAT_SCHEDULE = { 
#  'every-minute': { 
#   'task': 'tasks.add', 
#   'schedule': crontab(minute='*/1'), 
#   'args': (1,2), 
#  }, 
# } 

tasks.py Datei

from celery import Celery 
import time 

#Specify mongodb host and datababse to connect to 
BROKER_URL = 'mongodb://localhost:27017/jobs' 

celery = Celery('EOD_TASKS',broker=BROKER_URL) 

#Loads settings for Backend to store results of jobs 
celery.config_from_object('celeryconfig') 

@celery.task 
def add(x, y): 
    time.sleep(5) 
    return x + y 



# starting celery 
celery multi start worker --loglevel=info 
celery multi v4.1.0 (latentcall) 
> Starting nodes... 
    > [email protected]: OK 

laufen Sellerie Aufgabe

lnx-v2:171> python 
Python 3.4.1 (default, Nov 12 2014, 13:34:48) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from tasks import add 
>>> result = add.delay(1,1) 
>>> result 
<AsyncResult: 8e6ee263-d8a4-4b17-8d7a-9873b6c98473> 
>>> result.status 
'PENDING' 

Arbeiter log

lnx-v2:208> tail -f worker.log 
[2017-10-26 13:41:15,658: INFO/MainProcess] mingle: all alone 
[2017-10-26 13:41:15,683: INFO/MainProcess] [email protected] ready. 
[2017-10-26 13:45:50,465: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672// 
[2017-10-26 13:45:50,487: INFO/MainProcess] mingle: searching for neighbors 
[2017-10-26 13:45:51,522: INFO/MainProcess] mingle: all alone 
[2017-10-26 13:45:51,540: INFO/MainProcess] [email protected] ready. 
[2017-10-26 13:47:13,169: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672// 
[2017-10-26 13:47:13,191: INFO/MainProcess] mingle: searching for neighbors 
[2017-10-26 13:47:14,228: INFO/MainProcess] mingle: all alone 
[2017-10-26 13:47:14,254: INFO/MainProcess] [email protected] ready. 


# Celery process 
lnx-v2:209> ps -ef | grep celery 
15096  1 0 13:47 ?  00:00:00 [celeryd: [email protected]:MainProcess] -active- (worker --loglevel=info --logfile=worker%I.log --pidfile=worker.pid [email protected]) 
15157 15096 0 13:47 ?  00:00:00 [celeryd: [email protected]:ForkPoolWorker-1] 

Antwort

0

Prüfen Sie, ob das Add-Methode in Sellerie Aufgaben aus dem folgenden Code aufgeführt wird

celery.tasks.keys() 

Ich denke, der Dekorateur Sie mit Klammer schließen haben

@celery.task() 
def add(x, y): 
    time.sleep(5) 
    return x + y 
Verwandte Themen