SoFunction
Updated on 2024-11-18

Example content of Django using Celery plus redis to perform asynchronous tasks

Simple to use

Installing celery and redis

Defining celery tasks

New construction under the project

from celery import Celery

# Create an instance object of the Celery class
app = Celery('celery_task.tasks', broker='redis://127.0.0.1:6379/8')

# Define the task function
@
def send_register_active_email(message):
  with open("D:\\celery\\", 'a') as f:
    ("To perform a task..." + message)

Invoke the trigger task

from celery_tasks.tasks import send_register_active_email

def register():
  send_register_active_email.delay("test1\n")

if __name__ == "__main__":
  register()

Start celery in the project directory

celery -A tasks worker -l info

rerun

As shown, the task is received and executed successfully.

These are all the relevant points in this presentation, thank you for learning and supporting me.