저는 파이썬을 처음 접하고 실제로 제가 배우는 것을 배우려고합니다. 다른 사이트의 데이터를 가져 와서 웹 사이트를 통해 공용으로 표시하는 Python 스크립트가 있습니다. 나는 Heroku 배포판과 함께 장고를 사용하고있다.장고로 샐러리 데몬 화
정보를 업데이트하려면 아침에 스크립트를 자동으로 실행해야합니다. 셀러리가 최선의 선택이라는 것을 알았습니다. 나는 샐러리의 실제 예제를 가지고 있으며 장고로 제대로 구성했다고 생각한다. 그러나, 나는 또한 여기에 따라 대몬 화라고하는 프로세스를 통과해야합니다 : http://docs.celeryproject.org/en/latest/userguide/daemonizing.html 그래서 셀러리 작업자가 백그라운드에서 작동 할 수 있습니다.
여기가 난처한 곳이며 여기에 대한 단계별 자습서를 찾을 수 없습니다. 나는 사물이 작동하는 나는이 파일의 모든 필요하다고 생각 :
/etc/init.d/celeryd
/etc/defaults/celery
/etc/default/celerybeat
/project/celery.py
/project/__init__.py
내가 manage.py
는 내가 제대로 구성 celery.py
및 __init__.py
파일이 생각 을있는 루트 디렉토리에 시작이 모든 파일을 가지고있다. celery.py
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
app = Celery('project')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
및 init.py : 여기에 그들이있다
from __future__ import absolute_import, unicode_literals
# 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
__all__ = ['celery_app']
내가 제대로 다른 두 개의 파일을 구성하는 방법을 모르겠어요.
CELERYD_NODES=4
CELERY_BIN="project/celery"
CELERY_APP="project"
CELERYD_CHDIR="project/"
# Extra command-line arguments to the worker
#CELERYD_OPTS="--time-limit=300 --concurrency=8"
# Configure node-specific settings by appending node name to arguments:
#CELERYD_OPTS="--time-limit=300 -c 8 -c:worker2 4 -c:worker3 2 -Ofair:worker1"
# Set logging level to DEBUG
#CELERYD_LOG_LEVEL="DEBUG"
# %n will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_USER="celery"
CELERYD_GROUP="celery"
CELERY_CREATE_DIRS=1
여기에 celerybeat
파일입니다 : 여기 celeryd
을 위해 무엇을 가지고
# Absolute or relative path to the 'celery' command:
CELERY_BIN="project/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="project"
# or fully qualified:
#CELERY_APP="proj.tasks:app"
# Where to chdir at start.
CELERYBEAT_CHDIR="/project/"
# Extra arguments to celerybeat
#CELERYBEAT_OPTS="--schedule=/var/run/celery/celerybeat-schedule"
나는 또한 내가 다음 줄을 넣어하기로되어있어 정확한 위치를 잘 모르겠어요 :
을export DJANGO_SETTINGS_MODULE="settings"
나는 무엇이 /etc/defaults/celery
에 들어가는 지 정확히 알지 못한다. 나는 또한 내 작업 파일에 어쨌든 CELERY_BEAT
옵션의 주 파일이 포함되도록해야한다고 생각한다. 아직까지 이걸 못 받았지만 crontab 옵션을 여기에 넣을 수 있어야합니까?
대단히 감사합니다. Heroku와의 호환성을 확인하지 않았습니까? – juju