batch_test.py 1.49 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
from airflow import DAG
김진영's avatar
김진영 committed
6
from 'data/gasan_data' import gasanData
김진영's avatar
김진영 committed
7

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

김진영's avatar
김진영 committed
10
print(gasanData)
김진영's avatar
김진영 committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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
35
36
37
38
with DAG(
    'batch_test',
    default_args={
        'depends_on_past': False,
김진영's avatar
김진영 committed
39
        'email': 'kim-jy@lotte.net',
김진영's avatar
김진영 committed
40
41
    },
    description='Test Batch Job',
김진영's avatar
김진영 committed
42
    schedule_interval='*/1 * * * *',
김진영's avatar
김진영 committed
43
    start_date=datetime(2022, 5, 13, tzinfo=local_tz),
김진영's avatar
김진영 committed
44
    tags=['test'],
김진영's avatar
김진영 committed
45
    catchup=False,
김진영's avatar
김진영 committed
46
) as dag:
김진영's avatar
김진영 committed
47
48
    # gasan 작업 병렬처리
    post_gasan_tasks = []
김진영's avatar
김진영 committed
49

김진영's avatar
김진영 committed
50
    for i, data in enumerate(gasan_data):
김진영's avatar
김진영 committed
51
        post_gasan_task = BashOperator(
김진영's avatar
김진영 committed
52
53
            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
54
        )
김진영's avatar
김진영 committed
55

김진영's avatar
김진영 committed
56
        post_gasan_tasks.append(post_gasan_task)
김진영's avatar
김진영 committed
57

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