Asynchronous Tasks: Celery is Not Just For Soups Anymore

2 months ago
29

Run asynchronous tasks with Django, using Django & Celery.

You can use background tasks for things like image processing, text processing, external API calls, and more.

example/celery.py:

import os
from celery import Celery
from django.conf import settings
from celery import shared_task

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

app = Celery('example')
app.config_from_object('django.conf:settings', namespace='CELERY')

@shared_task
def my_task(arg1, arg2):
result = arg1 + arg2
return result

example/__init__.py:

from .celery import app as celery_app
__all__ = ["celery_app"]

Looking for help building your site? Need web hosting? Come check us out!

https://stockton-seo.com
https://superserverhero.com

Loading 1 comment...