Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Data Logistics Service
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
Container 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
eFlows4HPC WP2
Data Logistics Service
Commits
36c12439
Commit
36c12439
authored
3 years ago
by
Jedrzej Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
passing oid as parameter check
#4
parent
b18827f1
No related branches found
No related tags found
No related merge requests found
Pipeline
#77352
passed
3 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dags/b2shareoperator.py
+1
-1
1 addition, 1 deletion
dags/b2shareoperator.py
dags/taskflow.py
+20
-9
20 additions, 9 deletions
dags/taskflow.py
with
21 additions
and
10 deletions
dags/b2shareoperator.py
+
1
−
1
View file @
36c12439
...
...
@@ -21,7 +21,7 @@ def get_object_md(server, oid):
def
download_file
(
url
:
str
,
target_dir
:
str
):
fname
=
tempfile
.
mk
s
temp
(
dir
=
target_dir
)
fname
=
tempfile
.
mktemp
(
dir
=
target_dir
)
urllib
.
request
.
urlretrieve
(
url
=
url
,
filename
=
fname
)
return
fname
...
...
This diff is collapsed.
Click to expand it.
dags/taskflow.py
+
20
−
9
View file @
36c12439
"
Example of new taskflow api
"
from
airflow.decorators
import
dag
,
task
from
airflow.utils.dates
import
days_ago
from
airflow.models.connection
import
Connection
from
airflow.models.dagrun
import
DagRun
import
requests
import
urllib.request
import
tempfile
from
b2shareoperator
import
get_file_list
,
download_file
,
get_object_md
from
b2shareoperator
import
get_file_list
,
download_file
,
get_object_md
,
get_objects
default_args
=
{
'
owner
'
:
'
airflow
'
,
}
@dag
(
default_args
=
default_args
,
schedule_interval
=
None
,
start_date
=
days_ago
(
2
),
tags
=
[
'
example
'
])
def
taskflow_example
():
@task
()
def
extract
(
oid
:
str
):
def
taskflow_example
(
**
kwargs
):
@task
(
multiple_outputs
=
True
)
def
extract
(
**
kwargs
):
connection
=
Connection
.
get_connection_from_secrets
(
'
default_b2share
'
)
server
=
connection
.
get_uri
()
print
(
f
"
Rereiving data from
{
server
}
"
)
params
=
kwargs
[
'
params
'
]
if
'
oid
'
not
in
params
:
print
(
f
"
Missing object id in pipeline parameters
"
)
lst
=
get_objects
(
server
=
server
)
flist
=
{
o
[
'
id
'
]:
[
f
[
'
key
'
]
for
f
in
o
[
'
files
'
]]
for
o
in
lst
}
print
(
f
"
Objects on server:
{
flist
}
"
)
return
{}
else
:
oid
=
params
[
'
oid
'
]
obj
=
get_object_md
(
server
=
server
,
oid
=
oid
)
print
(
f
"
Object
:
{
obj
}
"
)
print
(
f
"
Retrieved object
{
oid
}
:
{
obj
}
"
)
flist
=
get_file_list
(
obj
)
return
flist
...
...
@@ -38,8 +48,9 @@ def taskflow_example():
def
load
(
files
:
dict
):
print
(
f
"
Total files downloaded:
{
len
(
files
)
}
"
)
data
=
extract
(
oid
=
'
b38609df2b334ea296ea1857e568dbea
'
)
data
=
extract
()
files
=
transform
(
data
)
load
(
files
)
dag
=
taskflow_example
()
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