Django

⌘K
  1. Home
  2. Django
  3. Django তে কিভাবে কাজ করতে...
  4. Celery
  5. ২. Install Celery

২. Install Celery

Celery Install করতে নিচের কমান্ডটি ব্যবহার করুন:

pip install celery

একটা মডার্ন Django এপ্লিকেশন এর ফোল্ডার স্ট্রাকচার দেখতে নিচের মতো হয়

- proj/
  - manage.py
  - proj/
    - __init__.py
    - settings.py
    - urls.py

Configure Celery

নতুন একটি celery ইনস্ট্যান্স বানাতে হবে একটি ফাইল তৈরী করি  proj/proj/celery.py

import os

from celery import Celery

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

app = Celery('proj')

# 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 apps.
app.autodiscover_tasks()


@app.task(bind=True, ignore_result=True)
def debug_task(self):
    print(f'Request: {self.request!r}')

proj এর জায়গায় আমাদের প্রজেক্ট এর নাম হবে

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')

app = Celery('proj')

init.py ফাইলে ফাইল টি অ্যাড করতে হবে

# 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',)

How can we help?