-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaily_dag.py
70 lines (65 loc) · 2.08 KB
/
daily_dag.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import datetime
from airflow import models
from airflow.operators import bash_operator
from airflow.contrib.operators.dataproc_operator import DataProcPySparkOperator
from airflow.contrib.operators import dataproc_operator
from airflow.providers.google.cloud.operators.dataproc import DataprocDeleteClusterOperator
current_date = datetime.datetime.now().date()
job_name = f"job_{current_date}"
default_dag_args = {
"start_date": datetime.datetime(2023, 8, 12)
, "retries": 3
, "retry_delay": datetime.timedelta(minutes=5)
, "email": "user@gmail.com"
, "email_on_failure": True
, "email_on_retry": True
}
with models.DAG("process_vnstock_data"
, schedule_interval = "0 9 * * 1-5"
, default_args = default_dag_args) as dag:
load_data = bash_operator.BashOperator(
task_id = "load_data"
, bash_command = "python3 /home/user/vnstock/src/data_processing/load_data.py"
, dag=dag
,
)
migrate_data = bash_operator.BashOperator(
task_id = "migrate_data"
, bash_command = "/home/user/vnstock/src/data_processing/migrate_data.sh "
, dag=dag
,
)
create_dataproc_cluster = dataproc_operator.DataprocClusterCreateOperator(
task_id = "create_dataproc_cluster"
, gcp_conn_id = "gcp_connection"
, project_id = "project_id"
, cluster_name = "my-cluster"
, region = "us-central1"
, num_workers = 2
, master_machine_type = "n1-standard-2"
, worker_machine_type="n1-standard-2"
, master_disk_size=50
, worker_disk_size=50
, dag=dag
,
)
submit_job = DataProcPySparkOperator(
task_id = "select_stock"
, gcp_conn_id = "gcp_connection"
, region = "us-central1"
, cluster_name = "my-cluster"
, main= "gs://growth_stock/py_script/growth_stock.py"
, job_name = job_name
, dag=dag
,
)
delete_cluster = DataprocDeleteClusterOperator(
task_id = "delete_cluster"
, gcp_conn_id = "gcp_connection"
, project_id = "project_id"
, cluster_name = "my-cluster"
, region = "us-central1"
, dag=dag
,
)
load_data >> migrate_data >> create_dataproc_cluster >> submit_job >> delete_cluster