blob: d59809aa4b44a49d578184425f1bb8280c0a9256 [file] [log] [blame]
Illyoung Choi39262742019-07-23 13:28:00 -07001# Copyright 2019-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""
16Example workflow using Airflow
17"""
18
19
20import logging
21from datetime import datetime
22from airflow import DAG
23from airflow.sensors.http_sensor import HttpSensor
24from airflow.operators.python_operator import PythonOperator
25
26log = logging.getLogger(__name__)
27
28args = {
29 # hard coded date
30 'start_date': datetime(2019, 1, 1),
31 'owner': 'iychoi'
32}
33
34dag = DAG(
35 dag_id='simple_airflow_workflow',
36 default_args=args,
37 # this dag will be triggered by external systems
38 schedule_interval=None
39)
40
41dag.doc_md = __doc__
42
43
44def handler(ds, **kwargs):
45 log.info('Handler is called!')
46 print(ds)
47 return
48
49
50def check_http(response):
51 content = response.text
52 if len(content) > 0:
53 log.info('the server responsed http content - %s' % content)
54 return True
55
56 log.info('the server did not respond')
57 return False
58
59
60sensor = HttpSensor(
61 task_id='http_sensor',
62 # 'http_default' goes to https://google.com
63 http_conn_id='http_default',
64 endpoint='',
65 request_params={},
66 response_check=check_http,
67 poke_interval=5,
68 dag=dag,
69)
70
71handler = PythonOperator(
72 task_id='python_operator',
73 provide_context=True,
74 python_callable=handler,
75 dag=dag
76)
77
78
79sensor >> handler