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
Merge requests
!89
Store Classification in local cache during create_classification
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Store Classification in local cache during create_classification
cache-create-classification
into
master
Overview
0
Commits
2
Pipelines
1
Changes
4
Merged
Eva Bardou
requested to merge
cache-create-classification
into
master
3 years ago
Overview
0
Commits
2
Pipelines
1
Changes
4
Expand
Closes
#56 (closed)
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
37f3d4fe
2 commits,
3 years ago
4 files
+
67
−
12
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
arkindex_worker/worker/classification.py
+
23
−
4
Options
@@ -2,9 +2,10 @@
import
os
from
apistar.exceptions
import
ErrorResponse
from
peewee
import
IntegrityError
from
arkindex_worker
import
logger
from
arkindex_worker.cache
import
CachedElement
from
arkindex_worker.cache
import
CachedClassification
,
CachedElement
from
arkindex_worker.models
import
Element
@@ -84,18 +85,36 @@ class ClassificationMixin(object):
return
try
:
self
.
request
(
created
=
self
.
request
(
"
CreateClassification
"
,
body
=
{
"
element
"
:
element
.
id
,
"
element
"
:
str
(
element
.
id
)
,
"
ml_class
"
:
self
.
get_ml_class_id
(
None
,
ml_class
),
"
worker_version
"
:
self
.
worker_version_id
,
"
confidence
"
:
confidence
,
"
high_confidence
"
:
high_confidence
,
},
)
except
ErrorResponse
as
e
:
if
self
.
use_cache
:
# Store classification in local cache
try
:
to_insert
=
[
{
"
id
"
:
created
[
"
id
"
],
"
element_id
"
:
element
.
id
,
"
class_name
"
:
ml_class
,
"
confidence
"
:
created
[
"
confidence
"
],
"
state
"
:
created
[
"
state
"
],
"
worker_version_id
"
:
self
.
worker_version_id
,
}
]
CachedClassification
.
insert_many
(
to_insert
).
execute
()
except
IntegrityError
as
e
:
logger
.
warning
(
f
"
Couldn
'
t save created classification in local cache:
{
e
}
"
)
except
ErrorResponse
as
e
:
# Detect already existing classification
if
(
e
.
status_code
==
400
Loading