Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/

postgres-data/
23 changes: 23 additions & 0 deletions dags/names_insertion_dag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pendulum
from airflow.models.dag import DAG
from airflow.operators.bash_operator import BashOperator

# Set the timezone to Indian Standard Time (IST)
local_tz = pendulum.timezone('Asia/Kolkata')

dag = DAG (
'names_insertion',
schedule_interval = '*/3 * * * *',
start_date = pendulum.datetime(2024, 3, 10, tz = local_tz),
catchup = False,
tags = ["POC", "POC1"]
)

update_csv = BashOperator(
task_id = "update_csv",
bash_command = 'python /opt/airflow/py_scripts/namaste_world.py',
dag = dag,
retries = 3,
)

update_csv
44 changes: 44 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "3.8"
services:
postgres:
image: postgres
platform: linux/arm64
env_file:
- .env
volumes:
- ./postgres-data:/var/lib/postgresql/data
scheduler:
image: apache/airflow
platform: linux/arm64
entrypoint: ./scripts/entrypoint.sh
deploy:
restart_policy:
condition: on-failure
depends_on:
- postgres
env_file:
- .env
volumes:
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
- ./py_scripts:/opt/airflow/py_scripts
- ./s3:/opt/airflow/s3
- ./scripts:/opt/airflow/scripts
webserver:
image: apache/airflow
platform: linux/arm64
deploy:
restart_policy:
condition: on-failure
command: webserver
depends_on:
- scheduler
env_file:
- .env
volumes:
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
- ./s3:/opt/airflow/s3
- ./py_scripts:/opt/airflow/py_scripts
ports:
- "8080:8080"
1 change: 1 addition & 0 deletions logs/scheduler/latest
10 changes: 10 additions & 0 deletions py_scripts/namaste_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# A py script to add a random entry the best_player.csv

import csv
import random

with open('/opt/airflow/s3/raw_data/best_player.csv', 'a+', newline='\n') as f:
writer = csv.writer(f, delimiter=',', quotechar="'", quoting=csv.QUOTE_MINIMAL)
writer.writerow([random.choice(["Virat Kohli", "Rohit Sharma"])])

print('Name Inserted')
7 changes: 7 additions & 0 deletions s3/raw_data/best_player.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
player_name, date
Virat Kohli, 2024-01-01
Rohit Sharma, 2024-01-02
Virat Kohli, 2024-01-03
Virat Kohli
Virat Kohli
Virat Kohli
5 changes: 5 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

airflow db migrate
airflow users create -r Admin -u admin -e admin@example.com -f admin -l user -p admin1234
airflow scheduler