-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassing_data_using_taskflow_api.py
More file actions
67 lines (49 loc) · 1.49 KB
/
passing_data_using_taskflow_api.py
File metadata and controls
67 lines (49 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import time
import json
from datetime import datetime,timedelta
from airflow.utils.dates import days_ago
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.decorators import task,dag
default_args={
'owner':'Bibek'
}
# Instantiate your DAG
@dag('cross_task_communication_taskflow', default_args=default_args,
tags=['python','dependencies','taskflow_api'], schedule_interval=None)
def passing_data_with_taskflow_api():
@task
def get_order_prices():
order_price_data={
'o1':234,
'o2':123,
'o3':45,
'o4':32,
'o5':97,
'o6':74
}
return order_price_data
@task
def compute_sum(order_price_data: dict):
total=0
for order in order_price_data:
total +=order_price_data[order]
return total
@task
def compute_avg(order_price_data: dict):
total=0
count=0
for order in order_price_data:
total +=order_price_data[order]
count +=1
average=total / count
return average
@task
def display_result(total: int, average:float):
print("Total price of goods is {total}".format(total=total))
print("Avg price of goods is {avgs}".format(avgs=average))
order_price_data=get_order_prices()
total=compute_sum(order_price_data)
average=compute_avg(order_price_data)
display_result(total,average)
passing_data_with_taskflow_api()