2017-10-26 9 views
0

백엔드 결과로 mongodb를 사용하여 셀러리를 실행하는 예제를 발견했습니다. original code example. 그의 예제에서 매분마다 실행할 매개 변수가있는 CELERYBEAT_SCHEDULE이 있습니다. 제 경우에는이 코드를 주석 처리했습니다. 필자의 경우에는 작업이 수신되는 즉시 실행하고 싶습니다. 작업자 로그에서 나는 작업이 수신되고 result.status에 대한 출력이 보류 중임을 알지 못합니다. 이 작업이 보류 상태에 있고 작업을 완료하지 않는 이유는 무엇입니까? 간단한 추가 작업 때문에 이미지가 오랜 시간이 걸릴 수 있습니다.셀러리 상태가 보류 중 상태로 고정됨

또 다른 점은 무엇 제가 같은 셀러리를 실행해야되는 말을 들었다에서 내가 가상 환경을 가지고있다 "셀러리 멀티 시작 노동자 --loglevel = 정보"

나는 셀러리 새로운 오전

이 나에게 약간 혼란 스럽다. 모든 도움을 미리 감사드립니다.

celeryconfig.py 파일

# 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 파일

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 

셀러리 작업을 실행

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' 

노동자 로그

,536 추가 방법은

celery.tasks.keys() 

난 당신이 괄호로 닫아야 할 데코레이터를 생각하는 다음 코드에서 셀러리 작업에 나열되어 있는지

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] 

답변

0

참조

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