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
8ef40d7d
Commit
8ef40d7d
authored
4 years ago
by
Eva Bardou
Committed by
Bastien Abadie
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use WORKER_VERSION_ID env var in helper methods
parent
5a9abdfe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!14
Use WORKER_VERSION_ID env var in helper methods
Pipeline
#77893
passed
4 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex_worker/worker.py
+7
-0
7 additions, 0 deletions
arkindex_worker/worker.py
tests/conftest.py
+5
-0
5 additions, 0 deletions
tests/conftest.py
tests/test_base_worker.py
+15
-0
15 additions, 0 deletions
tests/test_base_worker.py
with
27 additions
and
0 deletions
arkindex_worker/worker.py
+
7
−
0
View file @
8ef40d7d
...
...
@@ -30,6 +30,12 @@ class BaseWorker(object):
self
.
work_dir
=
os
.
path
.
join
(
xdg_data_home
,
"
arkindex
"
)
os
.
makedirs
(
self
.
work_dir
,
exist_ok
=
True
)
self
.
worker_version_id
=
os
.
environ
.
get
(
"
WORKER_VERSION_ID
"
)
if
not
self
.
worker_version_id
:
raise
Exception
(
"
Missing WORKER_VERSION_ID environment variable to start the Worker
"
)
logger
.
info
(
f
"
Worker will use
{
self
.
work_dir
}
as working directory
"
)
def
configure
(
self
):
...
...
@@ -192,6 +198,7 @@ class ElementsWorker(BaseWorker):
"
corpus
"
:
element
.
corpus
.
id
,
"
polygon
"
:
polygon
,
"
parent
"
:
element
.
id
,
"
worker_version
"
:
self
.
worker_version_id
,
},
)
self
.
report
.
add_element
(
element
.
id
,
type
)
This diff is collapsed.
Click to expand it.
tests/conftest.py
+
5
−
0
View file @
8ef40d7d
...
...
@@ -8,3 +8,8 @@ import pytest
def
pass_schema
(
responses
):
schema_url
=
os
.
environ
.
get
(
"
ARKINDEX_API_SCHEMA_URL
"
)
responses
.
add_passthru
(
schema_url
)
@pytest.fixture
(
autouse
=
True
)
def
give_worker_version_id_env_variable
(
monkeypatch
):
monkeypatch
.
setenv
(
"
WORKER_VERSION_ID
"
,
"
12341234-1234-1234-1234-123412341234
"
)
This diff is collapsed.
Click to expand it.
tests/test_base_worker.py
+
15
−
0
View file @
8ef40d7d
...
...
@@ -4,6 +4,8 @@ import os
import
sys
from
pathlib
import
Path
import
pytest
from
arkindex_worker
import
logger
from
arkindex_worker.worker
import
BaseWorker
...
...
@@ -12,6 +14,7 @@ def test_init_default_local_share():
worker
=
BaseWorker
()
assert
worker
.
work_dir
==
os
.
path
.
expanduser
(
"
~/.local/share/arkindex
"
)
assert
worker
.
worker_version_id
==
"
12341234-1234-1234-1234-123412341234
"
def
test_init_default_xdg_data_home
(
monkeypatch
):
...
...
@@ -20,6 +23,7 @@ def test_init_default_xdg_data_home(monkeypatch):
worker
=
BaseWorker
()
assert
worker
.
work_dir
==
f
"
{
path
}
/arkindex
"
assert
worker
.
worker_version_id
==
"
12341234-1234-1234-1234-123412341234
"
def
test_init_var_ponos_data_given
(
monkeypatch
):
...
...
@@ -28,6 +32,17 @@ def test_init_var_ponos_data_given(monkeypatch):
worker
=
BaseWorker
()
assert
worker
.
work_dir
==
f
"
{
path
}
/current
"
assert
worker
.
worker_version_id
==
"
12341234-1234-1234-1234-123412341234
"
def
test_init_var_worker_version_id_missing
(
monkeypatch
):
monkeypatch
.
delenv
(
"
WORKER_VERSION_ID
"
)
with
pytest
.
raises
(
Exception
)
as
e
:
BaseWorker
()
assert
(
str
(
e
.
value
)
==
"
Missing WORKER_VERSION_ID environment variable to start the Worker
"
)
def
test_cli_default
(
mocker
):
...
...
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