Created
January 29, 2023 13:33
-
-
Save vamsijakkula/5760a7da6994a6c7cc683109d7c0cb7a to your computer and use it in GitHub Desktop.
test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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