Looking for django Keywords? Try Ask4Keywords

Django 셀러리 구성


셀러리

  1. 설치 - pip install django-celery

  2. 더하다

  3. 기본 프로젝트 구조.

     - src/
       - bin/celery_worker_start # will be explained later on
       - logs/celery_worker.log
       - stack/__init __.py
       - stack/celery.py
       - stack/settings.py
       - stack/urls.py
       - manage.py
    
  4. celery.py 파일을 stack/stack/ 폴더에 추가하십시오.

     from __future__ import absolute_import
     import os
     from celery import Celery
     os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'stack.settings')
     from django.conf import settings  # noqa
     app = Celery('stack')
     app.config_from_object('django.conf:settings')
     app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
    
  5. stack/stack/__init__.py 다음 코드를 추가하십시오 :

     from __future__ import absolute_import
     from .celery import app as celery_app  # noqa
    
  6. 작업을 생성하고이를 @shared_task() 처럼 표시하십시오.

     @shared_task()
     def add(x, y):
         print("x*y={}".format(x*y))
    
  7. 셀러리 작업자를 "손으로"실행 :

    celery -A stack worker -l info 추가하려는 경우 celery -A stack worker -l info