Skip to content

Latest commit

 

History

History
77 lines (54 loc) · 1.08 KB

celery_reference.md

File metadata and controls

77 lines (54 loc) · 1.08 KB

Celery Reference

Running Celery

Worker-only

celery -A cfehome worker -l info

Beat-only (Scheduler-only)

celery -A cfehome beat -l info

Worker & Beat

celery -A cfehome worker -l info --beat

Using -l info is recommended in development, it's optional once in production.

Turn Functions into Celery Tasks

# myapp/tasks.py

def my_function(a=123, b=None, c=True):
    ...

becomes

# myapp/tasks.py
from celery import shared_task

@shared_task
def my_function(a=123, b=None, c=True):
    ...

or

# myapp/tasks.py
from celery import shared_task

@shared_task(name="my_function")
def my_function(a=123, b=None, c=True):
    ...

Running Celery Tasks

from myapp.tasks import my_function

Typical

my_function(a=456, b="Sweet", c=False)

Celery Shortcut

my_function.delay(a=456, b="Sweet", c=False)

Preferred Celery Call

delay_seconds = 15
my_function.apply_async(kwargs={"a": 456, "b": "Sweet", "c": False}, countdown=delay_seconds)