Skip to content

Coupon Code Scheduler Task and Configuration Documentation

This document provides an explanation of the Celery task responsible for managing coupon code validity and expirations, 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 CELERY namespace.
  • Auto-discovers tasks from installed Django apps.
  • Defines periodic task schedules using beat_schedule.

Task Description

1. Coupon Code Scheduler

This task ensures that expired and inactive coupon codes are updated in the system: - Runs daily at midnight (00:00) to deactivate expired coupons. - Checks coupon validity, disabling those that have passed their expiration date. - Ensures that users do not apply outdated coupons to purchases.

Key Points:

  • Automates the process of deactivating expired coupons.
  • Prevents invalid coupon usage and ensures smooth checkout processes.
  • Runs at a low-impact time (midnight) to minimize performance overhead.

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 enables flexible control over coupon expiration behavior.


Task Scheduling

Celery Beat is used to schedule tasks at predefined intervals. The schedule is defined in beat_schedule:

Scheduled Task:

  • Coupon Code Scheduler:
  • Runs: Every day at midnight (00:00).
  • Task Name: checkout.tasks.coupon_code_scheduler
  • Purpose: Updates coupon statuses to disable expired ones, ensuring only valid coupons remain active.