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
a2f33483
Commit
a2f33483
authored
9 months ago
by
ml bonhomme
Committed by
Erwan Rouchet
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Split project exports between two queues
parent
62e6f520
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2338
Split project exports between two queues
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex/documents/export/__init__.py
+11
-0
11 additions, 0 deletions
arkindex/documents/export/__init__.py
arkindex/documents/tests/test_export.py
+30
-9
30 additions, 9 deletions
arkindex/documents/tests/test_export.py
arkindex/project/triggers.py
+3
-1
3 additions, 1 deletion
arkindex/project/triggers.py
with
44 additions
and
10 deletions
arkindex/documents/export/__init__.py
+
11
−
0
View file @
a2f33483
...
...
@@ -135,7 +135,18 @@ def update_state(corpus_export: CorpusExport, state: CorpusExportState):
corpus_export
.
save
()
@job
(
"
high
"
,
timeout
=
settings
.
RQ_TIMEOUTS
[
"
export_corpus
"
])
def
local_export
(
corpus_export
:
CorpusExport
)
->
None
:
assert
corpus_export
.
source
==
"
default
"
export_corpus
(
corpus_export
)
@job
(
"
export
"
,
timeout
=
settings
.
RQ_TIMEOUTS
[
"
export_corpus
"
])
def
remote_export
(
corpus_export
:
CorpusExport
)
->
None
:
assert
corpus_export
.
source
!=
"
default
"
export_corpus
(
corpus_export
)
def
export_corpus
(
corpus_export
:
CorpusExport
)
->
None
:
_
,
db_path
=
tempfile
.
mkstemp
(
suffix
=
"
.db
"
)
try
:
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_export.py
+
30
−
9
View file @
a2f33483
...
...
@@ -5,6 +5,7 @@ from django.test import override_settings
from
django.urls
import
reverse
from
rest_framework
import
status
from
arkindex.documents.export
import
local_export
,
remote_export
from
arkindex.documents.models
import
Corpus
,
CorpusExportState
from
arkindex.project.tests
import
FixtureAPITestCase
from
arkindex.users.models
import
Role
...
...
@@ -12,7 +13,7 @@ from arkindex.users.models import Role
class
TestExport
(
FixtureAPITestCase
):
@patch
(
"
arkindex.project.triggers.export.export
_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
local_
export.delay
"
)
@override_settings
(
EXPORT_TTL_SECONDS
=
420
)
def
test_start
(
self
,
delay_mock
):
self
.
client
.
force_login
(
self
.
superuser
)
...
...
@@ -41,7 +42,7 @@ class TestExport(FixtureAPITestCase):
description
=
"
Export of corpus Unit Tests
"
))
@patch
(
"
arkindex.project.triggers.export.export
_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
local_
export.delay
"
)
def
test_start_requires_login
(
self
,
delay_mock
):
response
=
self
.
client
.
post
(
reverse
(
"
api:corpus-export
"
,
kwargs
=
{
"
pk
"
:
self
.
corpus
.
id
}))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_403_FORBIDDEN
)
...
...
@@ -49,7 +50,7 @@ class TestExport(FixtureAPITestCase):
self
.
assertFalse
(
self
.
corpus
.
exports
.
exists
())
self
.
assertFalse
(
delay_mock
.
called
)
@patch
(
"
arkindex.project.triggers.export.export
_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
local_
export.delay
"
)
def
test_start_requires_verified
(
self
,
delay_mock
):
self
.
user
.
verified_email
=
False
self
.
user
.
save
()
...
...
@@ -61,7 +62,7 @@ class TestExport(FixtureAPITestCase):
self
.
assertFalse
(
self
.
corpus
.
exports
.
exists
())
self
.
assertFalse
(
delay_mock
.
called
)
@patch
(
"
arkindex.project.triggers.export.export
_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
local_
export.delay
"
)
@patch
(
"
arkindex.users.utils.get_max_level
"
,
return_value
=
Role
.
Guest
.
value
)
def
test_start_requires_contributor
(
self
,
max_level_mock
,
delay_mock
):
self
.
user
.
rights
.
update
(
level
=
Role
.
Guest
.
value
)
...
...
@@ -75,7 +76,7 @@ class TestExport(FixtureAPITestCase):
self
.
assertFalse
(
self
.
corpus
.
exports
.
exists
())
self
.
assertFalse
(
delay_mock
.
called
)
@patch
(
"
arkindex.project.triggers.export.
export_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
remote_export
.delay
"
)
def
test_start_bad_source
(
self
,
delay_mock
):
self
.
client
.
force_login
(
self
.
superuser
)
...
...
@@ -87,7 +88,7 @@ class TestExport(FixtureAPITestCase):
self
.
assertFalse
(
delay_mock
.
called
)
@patch
(
"
arkindex.documents.models.CorpusExport.source
"
)
@patch
(
"
arkindex.project.triggers.export.
export_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
remote_export
.delay
"
)
@override_settings
(
EXPORT_TTL_SECONDS
=
420
)
def
test_start_with_source
(
self
,
delay_mock
,
source_field_mock
):
source_field_mock
.
field
.
choices
.
return_value
=
[(
"
default
"
,
"
default
"
),
(
"
jouvence
"
,
"
jouvence
"
)]
...
...
@@ -118,7 +119,7 @@ class TestExport(FixtureAPITestCase):
description
=
"
Export of corpus Unit Tests from source jouvence
"
))
@patch
(
"
arkindex.project.triggers.export.export
_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
local_
export.delay
"
)
def
test_start_running
(
self
,
delay_mock
):
self
.
client
.
force_login
(
self
.
superuser
)
self
.
corpus
.
exports
.
create
(
user
=
self
.
user
,
state
=
CorpusExportState
.
Running
)
...
...
@@ -133,7 +134,7 @@ class TestExport(FixtureAPITestCase):
self
.
assertFalse
(
delay_mock
.
called
)
@override_settings
(
EXPORT_TTL_SECONDS
=
420
)
@patch
(
"
arkindex.project.triggers.export.export
_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
local_
export.delay
"
)
def
test_start_recent_export
(
self
,
delay_mock
):
self
.
client
.
force_login
(
self
.
superuser
)
with
patch
(
"
django.utils.timezone.now
"
)
as
mock_now
:
...
...
@@ -153,7 +154,7 @@ class TestExport(FixtureAPITestCase):
self
.
assertFalse
(
delay_mock
.
called
)
@override_settings
(
EXPORT_TTL_SECONDS
=
420
)
@patch
(
"
arkindex.project.triggers.export.export
_corpus
.delay
"
)
@patch
(
"
arkindex.project.triggers.export.
local_
export.delay
"
)
def
test_start_recent_export_different_source
(
self
,
delay_mock
):
from
arkindex.documents.models
import
CorpusExport
CorpusExport
.
source
.
field
.
choices
=
[(
"
default
"
,
"
default
"
),
(
"
jouvence
"
,
"
jouvence
"
)]
...
...
@@ -433,3 +434,23 @@ class TestExport(FixtureAPITestCase):
response
=
self
.
client
.
delete
(
reverse
(
"
api:manage-export
"
,
kwargs
=
{
"
pk
"
:
export
.
id
}))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
assert
not
self
.
corpus
.
exports
.
exists
()
@patch
(
"
arkindex.documents.models.CorpusExport.source
"
)
def
test_local_export_default_db_only
(
self
,
source_field_mock
):
source_field_mock
.
field
.
choices
.
return_value
=
[(
"
default
"
,
"
default
"
),
(
"
jouvence
"
,
"
jouvence
"
)]
export
=
self
.
corpus
.
exports
.
create
(
user
=
self
.
superuser
,
state
=
CorpusExportState
.
Created
,
source
=
"
jouvence
"
)
with
self
.
assertRaises
(
AssertionError
):
local_export
(
export
)
export
.
refresh_from_db
()
self
.
assertEqual
(
export
.
state
,
CorpusExportState
.
Created
)
@patch
(
"
arkindex.documents.models.CorpusExport.source
"
)
def
test_remote_export_not_default_db
(
self
,
source_field_mock
):
source_field_mock
.
field
.
choices
.
return_value
=
[(
"
default
"
,
"
default
"
),
(
"
jouvence
"
,
"
jouvence
"
)]
export
=
self
.
corpus
.
exports
.
create
(
user
=
self
.
superuser
,
state
=
CorpusExportState
.
Created
,
source
=
"
default
"
)
with
self
.
assertRaises
(
AssertionError
):
remote_export
(
export
)
export
.
refresh_from_db
()
self
.
assertEqual
(
export
.
state
,
CorpusExportState
.
Created
)
This diff is collapsed.
Click to expand it.
arkindex/project/triggers.py
+
3
−
1
View file @
a2f33483
...
...
@@ -198,10 +198,12 @@ def export_corpus(corpus_export: CorpusExport) -> None:
"""
Export a corpus to a SQLite database
"""
export_function
=
export
.
local_export
description
=
f
"
Export of corpus
{
corpus_export
.
corpus
.
name
}
"
if
corpus_export
.
source
!=
"
default
"
:
description
+=
f
"
from source
{
corpus_export
.
source
}
"
export
.
export_corpus
.
delay
(
export_function
=
export
.
remote_export
export_function
.
delay
(
corpus_export
=
corpus_export
,
user_id
=
corpus_export
.
user_id
,
description
=
description
...
...
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