- type
- concept
- created
- Tue Apr 07 2026 02:00:00 GMT+0200 (Central European Summer Time)
- updated
- Tue Apr 07 2026 02:00:00 GMT+0200 (Central European Summer Time)
- sources
- raw/notes/activeContext, raw/notes/progress, raw/articles/DISCOVERIES
- tags
- celery beat tasks scheduling email newsletters expiry
Celery Beat Tasks
Architecture
- Broker: Redis (DB 1 on localhost)
- Worker process:
marketplace-celery-worker(PM2-managed) - Beat process:
marketplace-celery-beat(PM2-managed) - Configuration:
backend/config/celery.py
Scheduled Tasks
Email Polling for Ingestion (Every 5 Minutes)
Task: apps.ingestion.tasks.poll_ingestion_email
The ingestion pipeline supports receiving surplus lists via email. The beat task polls the ingestion email inbox every 5 minutes, looking for:
- Emails from verified mill senders
- Attachments matching expected file types (Excel, CSV)
- New messages not already processed
When found, it extracts attachments, creates IngestionBatch records, and triggers the processing pipeline (parse -> validate -> commit/reject).
Auto-Commit Trusted Batches
Task: apps.ingestion.tasks.auto_commit_trusted_batch
For mills marked as trusted (established relationship, consistent data quality), validated ingestion batches can be auto-committed without manual review. This task checks for validated batches from trusted mills and commits them, creating SurplusItems and triggering the matching algorithm.
Batch Processing
Task: apps.ingestion.tasks.process_ingestion_batch
Triggered when a new ingestion batch is created (either via email polling or manual upload). Processes the file through the full pipeline: file_processor (hash, validate) -> parser (column resolution, unit conversion) -> validator (field validation, dedup).
Newsletter Generation
Task: Newsletter generation and delivery tasks
Per-buyer personalized newsletters are generated based on the buyer's newsletter_frequency setting (daily, weekly, or on_match). The newsletter includes visibility-filtered surplus matches. Delivery tracking covers: generated -> sent -> delivered -> opened -> clicked (or bounced/failed).
Exclusivity Window Expiry
The exclusivity mechanism grants buyers 48-hour windows to negotiate on surplus items. When a window expires without a deal, Celery beat triggers the release, transitioning the item back to available status and optionally trying the next interested buyer (up to 3 grants per item).
Pre-Production Auto-Transition
Pre-production items have a future available_from date. Celery beat checks for items whose date has arrived and transitions them from pre_production to available status, making them visible to the matching algorithm and newsletter generation.
PM2 Process Configuration
The Celery processes are managed alongside the main API server:
| PM2 Name | Process | Notes |
|---|---|---|
| marketplace-api | gunicorn on port 8910 | Main API server |
| marketplace-celery-worker | Celery worker | Processes async tasks |
| marketplace-celery-beat | Celery beat | Triggers scheduled tasks |
All three processes are configured for auto-restart and log rotation via PM2.
Task Flow Diagram
Email Inbox
│ (every 5 min)
▼
poll_ingestion_email
│
▼
process_ingestion_batch
│
├── parse → validate
│
▼
auto_commit_trusted_batch (if trusted mill)
│
▼
SurplusItems created → matching triggered → newsletters generated
Sources
- raw/notes/activeContext -- Celery worker/beat operational status
- raw/notes/progress -- ingestion pipeline task details
- raw/articles/DISCOVERIES -- architecture and integration notes
Related
- wiki/entities/pm2-marketplace-stack -- PM2 process management details
- wiki/concepts/phases-0-to-13-recap -- Phase 1b (ingestion) and Phase 5 (newsletters) details
- wiki/summaries/checklist-summary -- Phase 1 ingestion pipeline tasks
- wiki/summaries/discoveries-summary -- Redis and Celery configuration
- wiki/concepts/database-credentials-and-roles -- Redis DB allocation