batch_test.py 1.43 KB
Newer Older
김진영's avatar
김진영 committed
1
2
from datetime import datetime, timedelta
from textwrap import dedent
김진영's avatar
김진영 committed
3
import pendulum
김진영's avatar
김진영 committed
4
from airflow.operators.bash import BashOperator
김진영's avatar
김진영 committed
5
6
from airflow import DAG

김진영's avatar
김진영 committed
7
8
local_tz = pendulum.timezone("Asia/Seoul")

김진영's avatar
김진영 committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# gasan 데이터 선언
gasan_data = [
	{
		"ip": "10.231.130.110",
		"serialNum": "7D0B3C9PAGFCF3C",
		"camName": "dt_lab_1"
	},
	{
		"ip": "10.231.130.111",
		"serialNum": "7D0B3C9PAG8D150",
		"camName": "dt_lab_2"
	},
	{
		"ip": "10.231.130.112",
		"serialNum": "7D0B3C9PAGBB838",
		"camName": "dt_lab_3"
	},
	{
		"ip": "10.231.130.113",
		"serialNum": "7D0B3C9PAG17F50",
		"camName": "dt_lab_4"
	},
]

김진영's avatar
김진영 committed
33
34
35
36
with DAG(
    'batch_test',
    default_args={
        'depends_on_past': False,
김진영's avatar
김진영 committed
37
        'email': 'kim-jy@lotte.net',
김진영's avatar
김진영 committed
38
39
    },
    description='Test Batch Job',
김진영's avatar
김진영 committed
40
    schedule_interval='*/1 * * * *',
김진영's avatar
김진영 committed
41
    start_date=datetime(2022, 5, 13, tzinfo=local_tz),
김진영's avatar
김진영 committed
42
    tags=['test'],
김진영's avatar
김진영 committed
43
    catchup=False,
김진영's avatar
김진영 committed
44
) as dag:
김진영's avatar
김진영 committed
45
46
    # gasan 작업 병렬처리
    post_gasan_tasks = []
김진영's avatar
김진영 committed
47

김진영's avatar
김진영 committed
48
    for i, data in enumerate(gasan_data):
김진영's avatar
김진영 committed
49
        post_gasan_task = BashOperator(
김진영's avatar
김진영 committed
50
51
            task_id='post_gasan'+str(i+1),
            bash_command="curl -X \'POST\' \'http://10.231.238.224:30999/api/v1/camera/writeimage\' -H \'Content-Type: application/json\' -d \'{\"id\": \"test\", \"pw\": \"test\", \"ip\": \"%s\", \"serialNum\": \"%s\", \"camName\": \"%s\"}\'" %(data["ip"], data["serialNum"], data["camName"]),
김진영's avatar
김진영 committed
52
        )
김진영's avatar
김진영 committed
53

김진영's avatar
김진영 committed
54
        post_gasan_tasks.append(post_gasan_task)
김진영's avatar
김진영 committed
55

김진영's avatar
김진영 committed
56
    post_gasan_tasks