Delete Expired Cart Items Task and Configuration Documentation
This document provides an explanation of the Celery task responsible for managing expired cart items, outlining its functionality and scheduling details.
Celery Setup Overview
Celery is configured to manage asynchronous tasks within the project. The Celery app is initialized in celery.py, which:
- Sets the default Django settings module.
- Configures Celery to use Django settings under the
CELERYnamespace. - Auto-discovers tasks from installed Django apps.
- Defines periodic task schedules using
beat_schedule.
Task Description
1. Delete Expired Cart Items
This task automatically removes expired cart items from the system: - Runs daily at midnight (00:00) to clear old and abandoned cart items. - Ensures that expired cart items do not occupy unnecessary storage. - Improves system efficiency by maintaining a clean cart database.
Key Points:
- Automates the cleanup of old cart items.
- Prevents outdated cart items from lingering indefinitely.
- Ensures smooth performance by reducing unnecessary database load.
Helper Function: Retrieve Configuration Values
A helper function is used to fetch custom configuration values from the CustomConfig table. If a value is not found, a default is returned. This allows for dynamic control over cart expiration settings.
Task Scheduling
Celery Beat is used to schedule tasks at predefined intervals. The schedule is defined in beat_schedule:
Scheduled Task:
- Delete Expired Cart Items:
- Runs: Every day at midnight (00:00).
- Task Name:
cart.tasks.delete_expired_cart_items - Purpose: Removes expired cart items to maintain a clean and efficient cart system.