Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Workers
Base Worker
Commits
4195b241
Commit
4195b241
authored
4 years ago
by
Bastien Abadie
Browse files
Options
Downloads
Patches
Plain Diff
Reload known ML classes when a 400 is received on creation
parent
a9aad29f
No related branches found
No related tags found
1 merge request
!30
Reload known ML classes when a 400 is received on creation
Pipeline
#78001
passed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker.py
+21
-5
21 additions, 5 deletions
arkindex_worker/worker.py
tests/test_elements_worker.py
+64
-0
64 additions, 0 deletions
tests/test_elements_worker.py
with
85 additions
and
5 deletions
arkindex_worker/worker.py
+
21
−
5
View file @
4195b241
...
...
@@ -8,6 +8,7 @@ import uuid
from
enum
import
Enum
from
pathlib
import
Path
import
apistar
import
gnupg
import
yaml
from
apistar.exceptions
import
ErrorResponse
...
...
@@ -296,11 +297,26 @@ class ElementsWorker(BaseWorker):
ml_class_id
=
self
.
classes
[
corpus_id
].
get
(
ml_class
)
if
ml_class_id
is
None
:
logger
.
info
(
f
"
Creating ML class
{
ml_class
}
on corpus
{
corpus_id
}
"
)
response
=
self
.
api_client
.
request
(
"
CreateMLClass
"
,
id
=
corpus_id
,
body
=
{
"
name
"
:
ml_class
}
)
ml_class_id
=
self
.
classes
[
corpus_id
][
ml_class
]
=
response
[
"
id
"
]
logger
.
debug
(
f
"
Created ML class
{
ml_class_id
}
"
)
try
:
response
=
self
.
api_client
.
request
(
"
CreateMLClass
"
,
id
=
corpus_id
,
body
=
{
"
name
"
:
ml_class
}
)
ml_class_id
=
self
.
classes
[
corpus_id
][
ml_class
]
=
response
[
"
id
"
]
logger
.
debug
(
f
"
Created ML class
{
response
[
'
id
'
]
}
"
)
except
apistar
.
exceptions
.
ErrorResponse
as
e
:
# Only reload for 400 errors
if
e
.
status_code
!=
400
:
raise
# Reload and make sure we have the class
logger
.
info
(
f
"
Reloading corpus classes to see if
{
ml_class
}
already exists
"
)
self
.
load_corpus_classes
(
corpus_id
)
assert
(
ml_class
in
self
.
classes
[
corpus_id
]
),
"
Missing class {ml_class} even after reloading
"
ml_class_id
=
self
.
classes
[
corpus_id
][
ml_class
]
return
ml_class_id
...
...
This diff is collapsed.
Click to expand it.
tests/test_elements_worker.py
+
64
−
0
View file @
4195b241
...
...
@@ -370,6 +370,70 @@ def test_get_ml_class_id(mock_elements_worker):
assert
ml_class_id
==
"
0000
"
def
test_get_ml_class_reload
(
responses
,
mock_elements_worker
):
corpus_id
=
"
12341234-1234-1234-1234-123412341234
"
# Add some initial classes
responses
.
add
(
responses
.
GET
,
f
"
http://testserver/api/v1/corpus/
{
corpus_id
}
/classes/
"
,
json
=
{
"
results
"
:
[
{
"
id
"
:
"
class1_id
"
,
"
name
"
:
"
class1
"
,
}
]
},
)
# Invalid response when trying to create class2
responses
.
add
(
responses
.
POST
,
f
"
http://testserver/api/v1/corpus/
{
corpus_id
}
/classes/
"
,
status
=
400
,
json
=
{
"
non_field_errors
"
:
"
Already exists
"
},
)
# Add both classes (class2 is created by another process)
responses
.
add
(
responses
.
GET
,
f
"
http://testserver/api/v1/corpus/
{
corpus_id
}
/classes/
"
,
json
=
{
"
results
"
:
[
{
"
id
"
:
"
class1_id
"
,
"
name
"
:
"
class1
"
,
},
{
"
id
"
:
"
class2_id
"
,
"
name
"
:
"
class2
"
,
},
]
},
)
# Simply request class 2, it should be reloaded
assert
mock_elements_worker
.
get_ml_class_id
(
corpus_id
,
"
class2
"
)
==
"
class2_id
"
assert
len
(
responses
.
calls
)
==
4
assert
mock_elements_worker
.
classes
==
{
corpus_id
:
{
"
class1
"
:
"
class1_id
"
,
"
class2
"
:
"
class2_id
"
,
}
}
assert
[(
call
.
request
.
method
,
call
.
request
.
url
)
for
call
in
responses
.
calls
]
==
[
(
"
GET
"
,
"
http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/
"
,
),
(
"
GET
"
,
f
"
http://testserver/api/v1/corpus/
{
corpus_id
}
/classes/?page=1
"
),
(
"
POST
"
,
f
"
http://testserver/api/v1/corpus/
{
corpus_id
}
/classes/
"
),
(
"
GET
"
,
f
"
http://testserver/api/v1/corpus/
{
corpus_id
}
/classes/?page=1
"
),
]
def
test_create_sub_element_wrong_element
(
mock_elements_worker
):
with
pytest
.
raises
(
AssertionError
)
as
e
:
mock_elements_worker
.
create_sub_element
(
...
...
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