Skip to content

Instantly share code, notes, and snippets.

@vamsijakkula
Created January 29, 2023 13:33
Show Gist options
  • Save vamsijakkula/5760a7da6994a6c7cc683109d7c0cb7a to your computer and use it in GitHub Desktop.
Save vamsijakkula/5760a7da6994a6c7cc683109d7c0cb7a to your computer and use it in GitHub Desktop.
test.py
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
import socket
import time
def get_host_info():
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
return host_name, host_ip
def print_host_info(**kwargs):
host_name, host_ip = get_host_info()
print(f"Host name: {host_name}")
print(f"Host IP: {host_ip}")
def sleep_task(**kwargs):
time.sleep(5)
dag = DAG(dag_id='fetch_host_info_dag',
schedule_interval=None,
start_date=datetime.today() - timedelta(minutes=60),)
print_host_info_task = PythonOperator(task_id='print_host_info', python_callable=print_host_info, dag=dag)
sleep_task = PythonOperator(task_id='sleep',
python_callable=sleep_task,
dag=dag)
print_host_info_task1 = PythonOperator(task_id= 'print_host_info1', python_callable=print_host_info,dag=dag)
print_host_info_task >> sleep_task >> print_host_info_task1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment