-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample_model_switch.py
53 lines (43 loc) · 1.7 KB
/
example_model_switch.py
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
"""
Example DAG where rekcurd_airflow plugins are used
"""
import airflow
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from rekcurd_airflow.operators import ModelSwitchOperator
from datetime import timedelta
default_args = {
'owner': 'rekcurd-airflow',
'depends_on_past': False,
'start_date': airflow.utils.dates.days_ago(2),
'email': [],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(seconds=5),
}
dag = DAG('example_model_switch', default_args=default_args, schedule_interval="@once")
def push_by_return(**kwargs):
return 5
"""
In production environment, ModelUploadOperator will return new model's model_id
"""
push_by_return = PythonOperator(task_id='push_by_return', dag=dag, python_callable=push_by_return)
# Rekcurd service (ID = 2. Application ID of the service is 1) will use the model whose ID is 3
switch = ModelSwitchOperator(task_id='switch_op',
project_id=1,
app_id='sample_app',
service_id=2,
model_id=3,
dag=dag)
# ModelSwitchOperator will receive the value returned by `model_provide_task`
# In this case, the switched model ID will be 5.
switch2 = ModelSwitchOperator(task_id='switch_op_xcom_return',
project_id=1,
app_id='sample_app',
service_id=2,
model_provide_task_id='push_by_return',
dag=dag)
# Switch model_id to 3 -> 5
switch.set_upstream(push_by_return)
switch2.set_upstream(switch)