Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
airflow-dags
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Team DB
airflow-dags
Commits
b575cb24
Commit
b575cb24
authored
2 months ago
by
edvs19
Browse files
Options
Downloads
Patches
Plain Diff
test
parent
7a18db03
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
dags.py
+1
-1
1 addition, 1 deletion
dags.py
teste_dag.py
+57
-57
57 additions, 57 deletions
teste_dag.py
with
58 additions
and
58 deletions
dags.py
+
1
−
1
View file @
b575cb24
This diff is collapsed.
Click to expand it.
teste_dag.py
+
57
−
57
View file @
b575cb24
import
datetime
from
airflow
import
DAG
from
airflow.decorators
import
dag
,
task
from
airflow.operators.empty
import
EmptyOperator
from
airflow.operators.bash
import
BashOperator
from
airflow.models.param
import
Param
from
airflow.providers.apache.spark.operators.spark_submit
import
SparkSubmitOperator
from
airflow.operators.trigger_dagrun
import
TriggerDagRunOperator
repo_home
=
'
/opt/airflow/dags/repo
'
############# PROCESS A SINGLE RECRODS FILE ###############
with
DAG
(
dag_id
=
"
process_records_teste
"
,
params
=
{
"
input_file
"
:
Param
(
"
invalid_file.jsonl
"
,
type
=
"
string
"
),
},
)
as
dag1
:
file
=
dag1
.
params
[
"
input_file
"
]
dag1
.
log
.
info
(
f
"
Input file
{
file
}
"
)
task_spark
=
SparkSubmitOperator
(
task_id
=
"
landing_to_bronze
"
,
application
=
f
"
{
repo_home
}
/gen_bronze.py
"
,
application_args
=
[
file
],
packages
=
"
org.apache.hadoop:hadoop-aws:3.3.4
"
)
task_dbt_setup
=
BashOperator
(
task_id
=
"
dbt_setup
"
,
bash_command
=
f
"
rm -rf /tmp/proj_teste && cp -r
{
repo_home
}
/proj_teste /tmp/proj_teste
"
,
)
task_bronze_to_gold
=
BashOperator
(
task_id
=
"
bronze_to_silver_to_gold
"
,
cwd
=
"
/tmp/proj_teste
"
,
bash_command
=
"
dbt deps && dbt build
"
,
)
task_spark
>>
task_dbt_setup
>>
task_bronze_to_gold
############# RUN TESTS DAG ##############
with
DAG
(
dag_id
=
"
run_tests
"
,
params
=
{
"
files
"
:
Param
([],
type
=
"
array
"
),
},
)
as
dag2
:
files
=
dag2
.
params
[
"
files
"
]
dag2
.
log
.
info
(
f
"
Input file
{
files
}
"
)
ops
=
[]
for
file
in
files
:
op
=
TriggerDagRunOperator
(
task_id
=
file
,
trigger_dag_id
=
dag1
.
dag_id
,
conf
=
{
"
input_file
"
:
file
}
)
ops
.
append
(
op
)
# Chain operators
if
len
(
ops
)
>
0
:
for
i
in
range
(
len
(
ops
)
-
1
):
ops
[
i
]
>>
ops
[
i
+
1
]
#
import datetime
#
from airflow import DAG
#
from airflow.decorators import dag, task
#
from airflow.operators.empty import EmptyOperator
#
from airflow.operators.bash import BashOperator
#
from airflow.models.param import Param
#
from airflow.providers.apache.spark.operators.spark_submit import SparkSubmitOperator
#
from airflow.operators.trigger_dagrun import TriggerDagRunOperator
#
repo_home = '/opt/airflow/dags/repo'
#
############# PROCESS A SINGLE RECRODS FILE ###############
#
with DAG(
#
dag_id="process_records_teste",
#
params={
#
"input_file": Param("invalid_file.jsonl", type="string"),
#
},
#
) as dag1:
#
file = dag1.params["input_file"]
#
dag1.log.info(f"Input file { file }")
#
task_spark = SparkSubmitOperator(
#
task_id="landing_to_bronze",
#
application=f"{repo_home}/gen_bronze.py",
#
application_args=[
#
file
#
],
#
packages="org.apache.hadoop:hadoop-aws:3.3.4"
#
)
#
task_dbt_setup = BashOperator(
#
task_id="dbt_setup",
#
bash_command=f"rm -rf /tmp/proj_teste && cp -r {repo_home}/proj_teste /tmp/proj_teste",
#
)
#
task_bronze_to_gold = BashOperator(
#
task_id="bronze_to_silver_to_gold",
#
cwd="/tmp/proj_teste",
#
bash_command="dbt deps && dbt build",
#
)
#
task_spark >> task_dbt_setup >> task_bronze_to_gold
#
############# RUN TESTS DAG ##############
#
with DAG(
#
dag_id="run_tests",
#
params={
#
"files": Param([], type="array"),
#
},
#
) as dag2:
#
files = dag2.params["files"]
#
dag2.log.info(f"Input file { files }")
#
ops = []
#
for file in files:
#
op = TriggerDagRunOperator(
#
task_id=file,
#
trigger_dag_id=dag1.dag_id,
#
conf={ "input_file": file }
#
)
#
ops.append(op)
#
# Chain operators
#
if len(ops) > 0:
#
for i in range(len(ops) - 1):
#
ops[i] >> ops[i + 1]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment