Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
452aa2d6
Commit
452aa2d6
authored
3 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Plain Diff
Merge branch 'delete-worker-runs-when-applying-templates' into 'master'
delete previous worker runs before applying the template Closes
#924
See merge request
!1580
parents
90b9df7b
d238fdb7
No related branches found
No related tags found
1 merge request
!1580
delete previous worker runs before applying the template
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/dataimport/serializers/imports.py
+3
-0
3 additions, 0 deletions
arkindex/dataimport/serializers/imports.py
arkindex/dataimport/tests/test_templates.py
+36
-4
36 additions, 4 deletions
arkindex/dataimport/tests/test_templates.py
with
39 additions
and
4 deletions
arkindex/dataimport/serializers/imports.py
+
3
−
0
View file @
452aa2d6
...
...
@@ -286,6 +286,9 @@ class ApplyProcessTemplateSerializer(ProcessACLMixin, serializers.Serializer):
# (from url id) onto the newly created one.
template_process
=
self
.
context
[
"
template
"
]
target_process
=
validated_data
[
"
process
"
]
# If the target process, already has worker runs, these will be deleted before applying the template
WorkerRun
.
objects
.
filter
(
dataimport_id
=
target_process
.
id
).
delete
()
# Apply the template by copying all the worker runs on to the new process
template_process
.
copy_runs
(
target_process
)
target_process
.
template_id
=
template_process
.
id
return
target_process
...
...
This diff is collapsed.
Click to expand it.
arkindex/dataimport/tests/test_templates.py
+
36
−
4
View file @
452aa2d6
...
...
@@ -254,7 +254,7 @@ class TestTemplates(FixtureAPITestCase):
def
test_apply_process_template
(
self
):
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
1
5
):
with
self
.
assertNumQueries
(
1
6
):
response
=
self
.
client
.
post
(
reverse
(
'
api:apply-process-template
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
template
.
id
)}),
data
=
json
.
dumps
({
"
process_id
"
:
str
(
self
.
dataimport
.
id
)}),
...
...
@@ -263,7 +263,39 @@ class TestTemplates(FixtureAPITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
json
()[
'
template_id
'
],
str
(
self
.
template
.
id
))
new_process_workers
=
WorkerRun
.
objects
.
select_related
(
'
version__worker
'
).
filter
(
dataimport__id
=
response
.
json
()[
"
id
"
])
child_run
,
parent_run
=
WorkerRun
.
objects
.
select_related
(
'
version__worker
'
).
filter
(
dataimport__id
=
response
.
json
()[
"
id
"
]).
order_by
(
'
version__worker__slug
'
).
all
()
# Check dependency
self
.
assertListEqual
(
child_run
.
parents
,
[
parent_run
.
id
])
# Check that every new worker_run is the same as one of the template's
self
.
assertTrue
(
self
.
dataimport_template
.
worker_runs
.
filter
(
version
=
parent_run
.
version
).
exists
())
self
.
assertTrue
(
self
.
dataimport_template
.
worker_runs
.
filter
(
version
=
child_run
.
version
).
exists
())
for
template_worker
in
self
.
template
.
worker_runs
.
all
():
self
.
assertTrue
(
new_process_workers
.
filter
(
version
=
template_worker
.
version
).
exists
())
def
test_apply_process_template_delete_previous_worker_runs
(
self
):
self
.
client
.
force_login
(
self
.
user
)
# Create a dataimport with one worker run already
dataimport
=
self
.
corpus
.
imports
.
create
(
creator
=
self
.
user
,
mode
=
DataImportMode
.
Workers
)
dataimport
.
worker_runs
.
create
(
version
=
self
.
version_2
,
parents
=
[],
)
# Apply a template that has two other worker runs
with
self
.
assertNumQueries
(
17
):
response
=
self
.
client
.
post
(
reverse
(
'
api:apply-process-template
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
template
.
id
)}),
data
=
json
.
dumps
({
"
process_id
"
:
str
(
dataimport
.
id
)}),
content_type
=
'
application/json
'
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
json
()[
'
template_id
'
],
str
(
self
.
template
.
id
))
# Assert that the previous worker runs was deleted and the template was correctly applied
child_run
,
parent_run
=
WorkerRun
.
objects
.
select_related
(
'
version__worker
'
).
filter
(
dataimport__id
=
response
.
json
()[
"
id
"
]).
order_by
(
'
version__worker__slug
'
).
all
()
# Check dependency
self
.
assertListEqual
(
child_run
.
parents
,
[
parent_run
.
id
])
# Check that every new worker_run is the same as one of the template's
self
.
assertTrue
(
self
.
template
.
worker_runs
.
filter
(
version
=
parent_run
.
version
).
exists
())
self
.
assertTrue
(
self
.
template
.
worker_runs
.
filter
(
version
=
child_run
.
version
).
exists
())
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