Ejemplo n.º 1
0
 def test_timedelta_sensor(self):
     op = TimeDeltaSensor(task_id='timedelta_sensor_check',
                          delta=timedelta(seconds=2),
                          dag=self.dag)
     op.run(start_date=DEFAULT_DATE,
            end_date=DEFAULT_DATE,
            ignore_ti_state=True)
Ejemplo n.º 2
0
 def test_timedelta_sensor_delta_2(self):
     op = TimeDeltaSensor(task_id='timedelta_sensor_check_delta_2',
                          delta=timedelta(minutes=2),
                          delta_on_upstream=True,
                          dag=self.dag)
     end_date = DEFAULT_DATE + timedelta(minutes=3)
     op.run(start_date=DEFAULT_DATE,
            end_date=end_date,
            ignore_ti_state=True)
import datetime
import airflow
from airflow import DAG
from airflow.models import Variable
from airflow.sensors.time_delta_sensor import TimeDeltaSensor

# get time delta sensor parameters
time_delta_args = Variable.get('time_delta_sensors', deserialize_json=True)

default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': airflow.utils.dates.days_ago(1),
    'email': '*****@*****.**',
    'retries': 2,
}

dag = DAG('time_delta_sensor',
          default_args=default_args,
          description='example DAG to test time delta sensor',
          catchup=False,
          schedule_interval='0 0 * * *')

wait_test = TimeDeltaSensor(task_id='wait_test',
                            delta=datetime.timedelta(
                                hours=time_delta_args['test']['hours'],
                                minutes=time_delta_args['test']['minutes']),
                            dag=dag)
 def test_timedelta_sensor(self):
     t = TimeDeltaSensor(
         task_id='timedelta_sensor_check',
         delta=timedelta(seconds=2),
         dag=self.dag)
     t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True)
    airflowTasksDict[task] = AirflowTask

for task in tasksDict.keys():
    if 'Dep' in tasksDict[task]:
        for dep in tasksDict[task]['Dep']:
            airflowTasksDict[task].set_upstream(airflowTasksDict[dep])

    if 'Pool' in tasksDict[task]:
        airflowTasksDict[task].pool = tasksDict[task]['Pool']

    if 'Priority' in tasksDict[task]:
        airflowTasksDict[task].priority_weight = tasksDict[task]['Priority']

    if 'StartTime' in tasksDict[task]:
        hour = tasksDict[task]['StartTime'][0]
        minute = tasksDict[task]['StartTime'][1]
        sensorTime = timedelta(hours=hour, minutes=minute)
        sensorTaskID = u'TimeSensor_{}_{}'.format(hour, minute)

        if sensorTaskID not in airflowTasksDict:
            SensorTask = TimeDeltaSensor(delta=sensorTime,
                                         task_id=sensorTaskID,
                                         pool='Sensors',
                                         dag=dag)
            airflowTasksDict[sensorTaskID] = SensorTask
        airflowTasksDict[task].set_upstream(airflowTasksDict[sensorTaskID])

if __name__ == '__main__':
    dag.clear(reset_dag_runs=True)
    dag.run()
Ejemplo n.º 6
0
)

dummyOperator = DummyOperator(
    task_id='DummyOperator',
    dag=dag,
)

dummyOperator2 = DummyOperator(
    task_id='DummyOperator2',
    dag=dag,
)

#timeSensor = TimeSensor(
#  task_id='TimeSensor',
#  dag=dag,
#  poke_interval=5,
#  target_time=time(20, 33, 0)
#)

bashOperator = BashOperator(
    task_id='BashOperator',
    bash_command='sleep 30',
    dag=dag,
)

timeDeltaSensor = TimeDeltaSensor(task_id='TimeDeltaSensor',
                                  dag=dag,
                                  poke_interval=5,
                                  delta=timedelta(seconds=20))

dummyOperator >> timeDeltaSensor >> dummyOperator2