This is a Django web application with Celery integrated for asynchronous task management. The project includes periodic tasks using Celery Beat and results stored in the Django database.
- Django 5.x based web application
- Asynchronous task processing with Celery
- Periodic task scheduling using Celery Beat
- Django REST Framework integration for APIs
- Celery tasks results stored in the Django database via
django-celery-results
-
Clone this repository:
git clone [email protected]:bmartins95/MyAdAgency.git cd MyAdAgency
-
Set up a virtual environment (optional but recommended):
2.1 MacOS or Linux:
python -m venv venv source venv/bin/activate
2.2 Windows:
python -m venv venv venv\Scripts\activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Apply the database migrations:
python manage.py migrate
-
Create a superuser (optional for accessing the Django admin interface):
python manage.py createsuperuser
To start the Django development server, run:
python manage.py runserver
Your app should now be running at http://127.0.0.1:8000/
.
To start the Celery worker, open a new terminal window and run:
celery -A app worker --loglevel=info
This will start the Celery worker and begin processing tasks.
To start Celery Beat, which schedules periodic tasks, run:
celery -A app beat --loglevel=info
Celery Beat will now handle the periodic tasks defined in CELERY_BEAT_SCHEDULE
.
-
Go to
http://127.0.0.1:8000/api/
to access the API root page: -
Create a new brand on
http://127.0.0.1:8000/api/brands/
: -
Create a new campaign on
http://127.0.0.1:8000/api/campaigns/
: -
Spend amount on campaign using
http://127.0.0.1:8000/api/campaigns/<campaign-id>/spend/
: -
Spend API successful response should be:
HTTP 200 OK Allow: POST, OPTIONS Content-Type: application/json Vary: Accept { "message": "Amount spent successfully." }
-
Unsuccessful response:
HTTP 202 ACCEPTED Allow: POST, OPTIONS Content-Type: application/json Vary: Accept { "message": "Amount spent successfully.", "reason": "Daily budget limit reached." }