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
b38754b5
Commit
b38754b5
authored
4 years ago
by
Eva Bardou
Browse files
Options
Downloads
Patches
Plain Diff
Store created elements in a local SQLite database
parent
33e8177b
No related branches found
No related tags found
1 merge request
!67
Store created elements in a local SQLite database
Pipeline
#78274
failed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/cache.py
+31
-0
31 additions, 0 deletions
arkindex_worker/cache.py
arkindex_worker/worker.py
+17
-0
17 additions, 0 deletions
arkindex_worker/worker.py
with
48 additions
and
0 deletions
arkindex_worker/cache.py
0 → 100644
+
31
−
0
View file @
b38754b5
# -*- coding: utf-8 -*-
import
os
import
sqlite3
class
LocalDB
(
object
):
def
__init__
(
self
,
path
):
if
not
os
.
path
.
exists
(
path
):
open
(
path
,
"
x
"
).
close
()
self
.
db
=
sqlite3
.
connect
(
path
)
self
.
cursor
=
self
.
db
.
cursor
()
def
create_elements_table
(
self
):
try
:
self
.
cursor
.
execute
(
"""
CREATE TABLE elements (
id TEXT PRIMARY KEY,
parent_id TEXT,
name TEXT NOT NULL,
type TEXT NOT NULL,
polygon TEXT,
worker_version_id TEXT
)
"""
)
except
sqlite3
.
OperationalError
:
print
(
"
Table
'
elements
'
already exists
"
)
def
insert
(
self
,
table
,
lines
):
self
.
cursor
.
executemany
(
f
"
INSERT INTO
{
table
}
VALUES (?,?,?,?,?,?)
"
,
lines
)
self
.
db
.
commit
()
This diff is collapsed.
Click to expand it.
arkindex_worker/worker.py
+
17
−
0
View file @
b38754b5
...
...
@@ -16,6 +16,7 @@ from apistar.exceptions import ErrorResponse
from
arkindex
import
ArkindexClient
,
options_from_env
from
arkindex_worker
import
logger
from
arkindex_worker.cache
import
LocalDB
from
arkindex_worker.models
import
Element
from
arkindex_worker.reporting
import
Reporter
...
...
@@ -451,6 +452,22 @@ class ElementsWorker(BaseWorker):
for
element
in
elements
:
self
.
report
.
add_element
(
parent
.
id
,
element
[
"
type
"
])
# Store elements in local cache
cache
=
LocalDB
(
f
"
/data/
{
os
.
environ
.
get
(
'
TASK_ID
'
)
}
/db.sqlite
"
)
cache
.
create_elements_table
()
to_insert
=
[
(
created_ids
[
idx
],
parent
.
id
,
element
[
"
name
"
],
element
[
"
type
"
],
json
.
dumps
(
element
[
"
polygon
"
]),
self
.
worker_version_id
,
)
for
idx
,
element
in
enumerate
(
elements
)
]
cache
.
insert
(
"
elements
"
,
to_insert
)
return
created_ids
def
create_transcription
(
self
,
element
,
text
,
type
=
None
,
score
=
None
):
...
...
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