Skip to content

Instantly share code, notes, and snippets.

@antweiss
Created April 23, 2023 15:32
Show Gist options
  • Save antweiss/d2740c248b0ddcdefc535303eb83494b to your computer and use it in GitHub Desktop.
Save antweiss/d2740c248b0ddcdefc535303eb83494b to your computer and use it in GitHub Desktop.
airflow pythonOperator example
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.utils.dates import days_ago
import time
with DAG(
'second',
start_date=days_ago(0),
description='Our new little DAG',
tags=['second']
) as dag:
def my_sleeping_function(random_base):
time.sleep(random_base)
for i in range(10): # loop in to create dynamic operators.
task = PythonOperator(
task_id='sleep_for_' + str(i), # unique task id
python_callable=my_sleeping_function, # python callable
op_kwargs={'random_base': i}, # pass the argument here
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment