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
4b27f506
Commit
4b27f506
authored
4 years ago
by
Eva Bardou
Browse files
Options
Downloads
Patches
Plain Diff
Add logic to merge parents caches into the current task one
parent
41204d06
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/cache.py
+16
-1
16 additions, 1 deletion
arkindex_worker/cache.py
arkindex_worker/worker.py
+21
-0
21 additions, 0 deletions
arkindex_worker/worker.py
with
37 additions
and
1 deletion
arkindex_worker/cache.py
+
16
−
1
View file @
4b27f506
...
...
@@ -42,7 +42,8 @@ def convert_table_tuple(table):
class
LocalDB
(
object
):
def
__init__
(
self
,
path
):
self
.
db
=
sqlite3
.
connect
(
path
)
self
.
path
=
path
self
.
db
=
sqlite3
.
connect
(
self
.
path
)
self
.
db
.
row_factory
=
sqlite3
.
Row
self
.
cursor
=
self
.
db
.
cursor
()
logger
.
info
(
f
"
Connection to local cache
{
path
}
established.
"
)
...
...
@@ -51,6 +52,20 @@ class LocalDB(object):
self
.
cursor
.
execute
(
SQL_ELEMENTS_TABLE_CREATION
)
self
.
cursor
.
execute
(
SQL_TRANSCRIPTIONS_TABLE_CREATION
)
def
merge_parents_caches
(
self
,
parents_cache_paths
):
for
idx
,
parent_cache
in
enumerate
(
parents_cache_paths
):
statements
=
[
"
PRAGMA page_size=80000;
"
,
"
PRAGMA synchronous=OFF;
"
,
f
"
ATTACH DATABASE
'
{
parent_cache
}
'
AS source
{
idx
}
;
"
,
f
"
REPLACE INTO elements SELECT * FROM source
{
idx
}
.elements;
"
,
f
"
REPLACE INTO transcriptions SELECT * FROM source
{
idx
}
.transcriptions;
"
,
]
for
statement
in
statements
:
self
.
cursor
.
execute
(
statement
)
self
.
db
.
commit
()
def
insert
(
self
,
table
,
lines
):
if
not
lines
:
return
...
...
This diff is collapsed.
Click to expand it.
arkindex_worker/worker.py
+
21
−
0
View file @
4b27f506
...
...
@@ -129,6 +129,27 @@ class BaseWorker(object):
# Load all required secrets
self
.
secrets
=
{
name
:
self
.
load_secret
(
name
)
for
name
in
required_secrets
}
# Merging parents caches (if there are any) in the current task local cache
if
self
.
cache
and
os
.
environ
.
get
(
"
TASK_ID
"
):
task
=
self
.
api_client
.
request
(
"
RetrieveTaskFromAgent
"
,
id
=
os
.
environ
.
get
(
"
TASK_ID
"
)
)
parents_cache_paths
=
[]
for
parent
in
task
[
"
parents
"
]:
parent_cache_path
=
f
"
/data/
{
parent
}
/db.sqlite
"
if
os
.
path
.
isfile
(
parent_cache_path
):
parents_cache_paths
.
append
(
parent_cache_path
)
if
len
(
parents_cache_paths
)
==
1
:
with
open
(
self
.
cache
.
path
,
"
rb+
"
)
as
cache_file
,
open
(
parents_cache_paths
[
0
],
"
rb
"
)
as
parent_cache_file
:
cache_file
.
truncate
(
0
)
cache_file
.
write
(
parent_cache_file
.
read
())
elif
len
(
parents_cache_paths
)
>
1
:
self
.
cache
.
merge_parent_caches
(
parents_cache_paths
)
def
load_secret
(
self
,
name
):
"""
Load all secrets described in the worker configuration
"""
secret
=
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