Paket Special Novel Animal FarmGeorge Orwell’s Nineteen Eighty-Four is one of the most famous and influential novels of the 20th century. This terrifying dystopia, which he created in a time of great social and political unrest, remains acutely relevant and influential to this day. Free Klik Disini ! |
Pada artikel sebelumnya kita telah membuat app django dan juga sudah mengintegrasikan django dan redis, baca artikel sebelumnya :
pip install celery redis
paste kode dibawah ini kedalam file celery.py
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'firstproject.settings')
app = Celery('firstproject')# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
# app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
Selanjutnya integrasikan celery dengan django, caranya panggil function yang sudah kita buat tadi dan simpan di file __init__.py. Posisi direktory __init__.py masih sama dengan celery.py, perhatikan kode dibawah ini
from __future__ import absolute_import# 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
Tambahkan variable REDIS_BROKER_URL pada file settings.py
CELERY_BROKER_URL = env('BROKER_URL', default='redis://localhost:6379')
celery -A firstproject worker -l info