Skip to content

Instantly share code, notes, and snippets.

@AliRn76
Created November 21, 2022 09:20
Show Gist options
  • Save AliRn76/0b48534c654170bd1f679a08beb6d859 to your computer and use it in GitHub Desktop.
Save AliRn76/0b48534c654170bd1f679a08beb6d859 to your computer and use it in GitHub Desktop.
Celery with Redis
import os
from pathlib import Path
from celery import Celery
from dotenv import dotenv_values
BASE_DIR = Path(__file__).resolve().parent.parent
env = dotenv_values(BASE_DIR / '.env')
REDIS_HOST = env['REDIS_HOST']
REDIS_PORT = env['REDIS_PORT']
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
celery_app = Celery('lms-exam', broker=f'redis://{REDIS_HOST}:{REDIS_PORT}')
celery_app.config_from_object('django.conf:settings', namespace='CELERY')
celery_app.autodiscover_tasks()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment