This repository contains the code for the Apache Airflow simulation project. The goal of the project is to demonstrate the capabilities of Apache Airflow in managing workflows and data pipelines.
This project integrates Django and Apache Airflow to dynamically generate DAGs based on a Simulator model. Each DAG schedules tasks to generate random values, call a KPI endpoint, and process the response.
-
Download and set up Airflow using Docker.
-
Create dags, logs, and plugins folders.
-
Use docker-compose.yaml to start Airflow.
-
Access the Airflow UI at http://localhost:8080.
-
Create a Django project with simulator and kpis apps.
-
Add the Simulator model and the KPI endpoint.
-
Run migrations and start the Django server.
-
Test endpoints using Postman.
-
Dynamic DAGs are created in dynamic_dags.py based on Simulator model instances.
-
DAGs fetch random values and call the KPI endpoint.
-
Run the Django development server:
python manage.py runserver
-
Open the admin interface at http://127.0.0.1:8000/admin and add Simulator instances.
-
Test the KPI endpoint using Postman:
- URL: http://127.0.0.1:8000/api/kpis/kpi/
- Method: POST
- Body (JSON):
{ "value": 100, "kpi_id": 1 }
- Expected Response:
{ "input_value": 100, "kpi_id": 1, "result": 600.0 }
- Start Airflow using Docker:
docker-compose up airflow-init docker-compose up
- Access the Airflow UI at http://localhost:8080.
- Verify the dynamically created DAGs for each Simulator instance.
- Trigger a DAG manually and monitor the task execution.
- Check the logs in the Airflow UI to ensure tasks are executed successfully.
-
Clone the repository:
git clone https://github.com/hebaraslan2001/airflow_simulation.git
-
Install the required dependencies:
cd airflow_simulation pip install -r requirements.txt