python-async-workers

python-async-workers

Generate Python background workers, cron jobs, message queue consumers. Use when creating scheduled tasks (APScheduler), Celery workers, RabbitMQ/Redis queue consumers, or async job processing. Follows project async patterns and integrates with existing services.

0
0포크
업데이트됨 1/19/2026
SKILL.md
readonlyread-only
name
python-async-workers
description

Generate Python background workers, cron jobs, message queue consumers. Use when creating scheduled tasks (APScheduler), Celery workers, RabbitMQ/Redis queue consumers, or async job processing. Follows project async patterns and integrates with existing services.

Python Async Workers

Background processing patterns for FastAPI applications.

Architecture Overview

┌─────────────────────────────────────────────────────────────┐
│                      FastAPI Application                     │
├─────────────────────────────────────────────────────────────┤
│  API Request  │  Cron Scheduler  │  Queue Consumer          │
│      ↓        │        ↓         │        ↓                 │
│  Enqueue Job  │  Trigger Task    │  Process Message         │
│      ↓        │        ↓         │        ↓                 │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                   Service Layer                      │   │
│  │              (Shared Business Logic)                 │   │
│  └─────────────────────────────────────────────────────┘   │
│      ↓                   ↓                  ↓               │
│  Message Queue      Database            External APIs       │
│  (RabbitMQ/Redis)   (PostgreSQL)                            │
└─────────────────────────────────────────────────────────────┘

Components

Component Purpose Location
Cron Jobs Scheduled recurring tasks app/jobs/
Celery Tasks Distributed task queue app/tasks/
Queue Consumers Message processing app/consumers/
Workers Background processors app/workers/

When to Use What

Use Case Solution
Run every X minutes/hours Cron (APScheduler)
Async processing after API call Celery Task
Process messages from external system Queue Consumer
Long-running background process Worker with asyncio
Distributed across multiple servers Celery + RabbitMQ
Simple in-process background FastAPI BackgroundTasks

Key Principles

1. Reuse Service Layer

Workers should call existing services, not duplicate logic:

# GOOD: Reuse service
async def process_order(order_id: int):
    async with get_session() as session:
        service = OrderService(session)
        await service.process(order_id)

# BAD: Duplicate logic in worker
async def process_order(order_id: int):
    # Don't copy-paste service code here!
    pass

2. Idempotency

All background tasks must be idempotent (safe to retry):

# GOOD: Check before processing
async def send_email(user_id: int, email_type: str):
    if await was_email_sent(user_id, email_type):
        return  # Already sent, skip
    await do_send_email(user_id, email_type)
    await mark_email_sent(user_id, email_type)

3. Error Handling

Always handle errors gracefully with retries:

@celery.task(bind=True, max_retries=3)
def process_payment(self, payment_id: int):
    try:
        # Process
        pass
    except TransientError as e:
        raise self.retry(exc=e, countdown=60)
    except PermanentError as e:
        # Log and don't retry
        logger.error(f"Payment {payment_id} failed permanently: {e}")

Reference Navigation

Scheduling:

Task Queues:

Message Queues:

Integration with python-backend-development

This skill extends python-backend-development:

  • Workers call Services from app/services/
  • Use same Repository pattern for database access
  • Follow same async patterns (async def, await)
  • Use same error handling (custom exceptions)
  • Share configuration from app/core/config.py

You Might Also Like

Related Skills

coding-agent

coding-agent

179Kdev-codegen

Run Codex CLI, Claude Code, OpenCode, or Pi Coding Agent via background process for programmatic control.

openclaw avataropenclaw
받기
add-uint-support

add-uint-support

97Kdev-codegen

Add unsigned integer (uint) type support to PyTorch operators by updating AT_DISPATCH macros. Use when adding support for uint16, uint32, uint64 types to operators, kernels, or when user mentions enabling unsigned types, barebones unsigned types, or uint support.

pytorch avatarpytorch
받기
at-dispatch-v2

at-dispatch-v2

97Kdev-codegen

Convert PyTorch AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code. Use when porting AT_DISPATCH_ALL_TYPES_AND*, AT_DISPATCH_FLOATING_TYPES*, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.

pytorch avatarpytorch
받기
skill-writer

skill-writer

97Kdev-codegen

Guide users through creating Agent Skills for Claude Code. Use when the user wants to create, write, author, or design a new Skill, or needs help with SKILL.md files, frontmatter, or skill structure.

pytorch avatarpytorch
받기

Implements JavaScript classes in C++ using JavaScriptCore. Use when creating new JS classes with C++ bindings, prototypes, or constructors.

oven-sh avataroven-sh
받기

Creates JavaScript classes using Bun's Zig bindings generator (.classes.ts). Use when implementing new JS APIs in Zig with JSC integration.

oven-sh avataroven-sh
받기