agentleFS
agenticlukeagenticluke/django-celery-jobs-plus/skill/SKILL.md

django-celery

Skill0 starsChanged 2 months agoMITView on GitHub

Run Django jobs in the background with Celery. Covers task queues, workers, retries, schedules, and Redis or RabbitMQ.

  • Installs packages

6 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions6 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 6

    1. Fmarzochi/EGC★ 61same name
    2. gongyijie85/dsh-ecc★ 8same name
    3. AndresArreguy/ecc-pi-port★ 1same name
    4. SamuelNDCE/claude-super-skill-library★ 1same name
    5. davidanthonyn/claude-skills★ 0same name
    6. renepf/claude-skills★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

The file

Show its rules and text

We split this skill into the rules it gives an agent

17 rules. About 0 are common, 15 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈15

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use Celery to run slow Django work outside web requests.

    line 9
  2. Distinctive:

    call an API without making the user wait.

    line 15
  3. Distinctive:

    Run jobs at set times.

    line 16
  4. Distinctive:

    Do not use Celery for work that must finish before the page loads.

    line 19
  5. Distinctive:

    Add this to Django settings:

    line 39
  6. Distinctive:

    Keep the broker URL in an env file when it has a password.

    line 48
  7. Very specific:

    Add this to myapp/__init__.py:

    line 66
  8. Distinctive:

    Run at least one worker in each live app setup.

    line 112
  9. Distinctive:

    If the task depends on saved data, queue it after the database change is done:

    line 122
  10. Distinctive:

    Run only one scheduler. Two schedulers may send the same task twice.

    line 155
  11. Distinctive:

    Do not retry bad input.

    line 212
  12. Distinctive:

    Keep failed tasks so they can be checked or run again.

    line 216
  13. Distinctive:

    Use a dead-letter queue when the broker supports it.

    line 217
  14. Distinctive:

    Do not log passwords, tokens, or private user data.

    line 218
  15. Distinctive:

    Before sending money, email, or a web request, check if the work was already done.

    line 224
  16. Distinctive:

    Keep tasks small. Pass file paths or record IDs instead of large files.

    line 226
  17. Very specific:

    Do not wait for one task inside another task with .get().

    line 228

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Django and Celery Tasks

Use Celery to run slow Django work outside web requests.

Use This Skill When

  • Send email in the background.
  • Run slow jobs.
  • call an API without making the user wait.
  • Run jobs at set times.
  • Split a large job into small jobs.

Do not use Celery for work that must finish before the page loads.

Setup

1. Install Celery

For Redis:

pip install celery redis

For RabbitMQ:

pip install celery

2. Set the Broker

Add this to Django settings:

CELERY_BROKER_URL = "redis://localhost:6379/0"
CELERY_RESULT_BACKEND = "redis://localhost:6379/1"
CELERY_TASK_TIME_LIMIT = 300
CELERY_TASK_SOFT_TIME_LIMIT = 270

Keep the broker URL in an env file when it has a password.

3. Create the Celery App

Create myapp/celery.py:

import os

from celery import Celery

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")

app = Celery("myapp")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()

Add this to myapp/__init__.py:

from .celery import app as celery_app

__all__ = ("celery_app",)

Change myapp to the name of your Django project.

4. Write a Task

Create emails/tasks.py:

from celery import shared_task
from django.core.mail import send_mail


@shared_task(
    autoretry_for=(Exception,),
    retry_backoff=True,
    retry_jitter=True,
    retry_kwargs={"max_retries": 5},
)
def send_welcome_email(user_id):
    from django.contrib.auth import get_user_model

    user = get_user_model().objects.get(pk=user_id)

    send_mail(
        subject="Welcome",
        message="Thanks for joining.",
        from_email=None,
        recipient_list=[user.email],
    )

Pass IDs, text, numbers, lists, or maps to tasks. Do not pass Django model objects.

5. Start a Worker

celery -A myapp worker --loglevel=INFO

Run at least one worker in each live app setup.

Queue a Task

from emails.tasks import send_welcome_email

send_welcome_email.delay(user.id)

If the task depends on saved data, queue it after the database change is done:

from django.db import transaction

transaction.on_commit(
    lambda: send_welcome_email.delay(user.id)
)

This keeps the worker from reading data before it is saved.

Run Tasks on a Schedule

Add this to myapp/celery.py:

from celery.schedules import crontab

app.conf.beat_schedule = {
    "send-report-daily": {
        "task": "reports.tasks.send_report",
        "schedule": crontab(hour=9, minute=0),
    },
}

Start the scheduler:

celery -A myapp beat --loglevel=INFO

Run only one scheduler. Two schedulers may send the same task twice.

Set the time zone in Django settings:

TIME_ZONE = "America/Chicago"
USE_TZ = True
CELERY_TIMEZONE = TIME_ZONE

Concrete Example

Queue an image resize after an upload is saved:

# photos/tasks.py
from celery import shared_task


@shared_task(bind=True, max_retries=3)
def resize_photo(self, photo_id):
    from .models import Photo

    try:
        photo = Photo.objects.get(pk=photo_id)
        photo.make_thumbnail()
    except Photo.DoesNotExist:
        return
    except OSError as error:
        raise self.retry(exc=error, countdown=30)
# photos/views.py
from django.db import transaction
from django.shortcuts import redirect

from .forms import PhotoForm
from .tasks import resize_photo


def upload_photo(request):
    form = PhotoForm(request.POST, request.FILES)

    if form.is_valid():
        photo = form.save()
        transaction.on_commit(
            lambda: resize_photo.delay(photo.id)
        )
        return redirect("photo-detail", pk=photo.id)

The page can return at once. The worker resizes the photo later.

Error Rules

  • Retry short network or broker errors.
  • Do not retry bad input.
  • Set a retry limit.
  • Set a time limit for slow tasks.
  • Log the task name and record ID.
  • Keep failed tasks so they can be checked or run again.
  • Use a dead-letter queue when the broker supports it.
  • Do not log passwords, tokens, or private user data.

Safe Task Rules

A task may run more than once. Write it so a second run is safe.

Before sending money, email, or a web request, check if the work was already done. Use a unique key or a saved status when needed.

Keep tasks small. Pass file paths or record IDs instead of large files.

Do not wait for one task inside another task with .get(). Queue the next task instead.

Checks Before Release

  • The broker is running.
  • The worker can load Django settings.
  • The task is found by Celery.
  • Retries have a limit.
  • Slow tasks have a time limit.
  • Tasks are safe to run twice.
  • Tasks are queued after database commit.
  • Only one scheduler is running.
  • Worker logs are saved.
  • Failed jobs can be checked and run again.
  • Workers stop in a safe way during release.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.