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
f08a8e42
Commit
f08a8e42
authored
1 year ago
by
Yoann Schneider
Committed by
Bastien Abadie
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
More explicit error message when corpus_id is not set in environment
parent
18a1b556
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!404
More explicit error message when corpus_id is not set in environment
Pipeline
#136118
passed
1 year ago
Stage: release
Changes
3
Pipelines
8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex_worker/worker/base.py
+14
-7
14 additions, 7 deletions
arkindex_worker/worker/base.py
tests/conftest.py
+9
-0
9 additions, 0 deletions
tests/conftest.py
tests/test_base_worker.py
+23
-1
23 additions, 1 deletion
tests/test_base_worker.py
with
46 additions
and
8 deletions
arkindex_worker/worker/base.py
+
14
−
7
View file @
f08a8e42
...
...
@@ -140,7 +140,7 @@ class BaseWorker(object):
self
.
process_information
=
None
# corpus_id will be updated in configure() using the worker_run's corpus
# or in configure_for_developers() from the environment
self
.
corpus_id
=
None
self
.
_
corpus_id
=
None
self
.
user_configuration
=
{}
self
.
model_configuration
=
{}
self
.
support_cache
=
support_cache
...
...
@@ -155,6 +155,17 @@ class BaseWorker(object):
# Define API Client
self
.
setup_api_client
()
@property
def
corpus_id
(
self
)
->
str
:
"""
ID of the corpus on which the worker is executed.
Has to be set through the `ARKINDEX_CORPUS_ID` variable in **read-only** mode.
Raises an Exception when trying to access when unset.
"""
if
not
self
.
_corpus_id
:
raise
Exception
(
"
Missing ARKINDEX_CORPUS_ID environment variable
"
)
return
self
.
_corpus_id
@property
def
is_read_only
(
self
)
->
bool
:
"""
...
...
@@ -199,11 +210,7 @@ class BaseWorker(object):
logger
.
warning
(
"
Running without any extra configuration
"
)
# Define corpus_id from environment
self
.
corpus_id
=
os
.
environ
.
get
(
"
ARKINDEX_CORPUS_ID
"
)
if
not
self
.
corpus_id
:
logger
.
warning
(
"'
ARKINDEX_CORPUS_ID
'
was not set in the environment. Any API request involving a `corpus_id` will fail.
"
)
self
.
_corpus_id
=
os
.
environ
.
get
(
"
ARKINDEX_CORPUS_ID
"
)
# Define model_version_id from environment
self
.
model_version_id
=
os
.
environ
.
get
(
"
ARKINDEX_MODEL_VERSION_ID
"
)
...
...
@@ -229,7 +236,7 @@ class BaseWorker(object):
self
.
process_information
=
worker_run
[
"
process
"
]
# Load corpus id
self
.
corpus_id
=
worker_run
[
"
process
"
][
"
corpus
"
]
self
.
_
corpus_id
=
worker_run
[
"
process
"
][
"
corpus
"
]
# Load worker version information
worker_version
=
worker_run
[
"
worker_version
"
]
...
...
This diff is collapsed.
Click to expand it.
tests/conftest.py
+
9
−
0
View file @
f08a8e42
...
...
@@ -211,6 +211,15 @@ def mock_elements_worker(monkeypatch, mock_worker_run_api):
return
worker
@pytest.fixture
def
mock_elements_worker_read_only
(
monkeypatch
):
"""
Build and configure an ElementsWorker with fixed CLI parameters to avoid issues with pytest
"""
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
,
"
--dev
"
])
worker
=
ElementsWorker
()
worker
.
configure
()
return
worker
@pytest.fixture
def
mock_elements_worker_with_list
(
monkeypatch
,
responses
,
mock_elements_worker
):
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_base_worker.py
+
23
−
1
View file @
f08a8e42
...
...
@@ -10,7 +10,7 @@ import pytest
from
arkindex.mock
import
MockApiClient
from
arkindex_worker
import
logger
from
arkindex_worker.worker
import
BaseWorker
from
arkindex_worker.worker
import
BaseWorker
,
ElementsWorker
from
arkindex_worker.worker.base
import
ModelNotFoundError
from
tests.conftest
import
FIXTURES_DIR
...
...
@@ -739,3 +739,25 @@ def test_extract_parent_archives(tmp_path):
)
mode
=
"
rb
"
if
extracted_file
.
suffix
==
"
.png
"
else
"
r
"
assert
extracted_file
.
open
(
mode
).
read
()
==
expected_file
.
open
(
mode
).
read
()
def
test_corpus_id_not_set_read_only_mode
(
mock_elements_worker_read_only
:
ElementsWorker
,
):
mock_elements_worker_read_only
.
configure
()
with
pytest
.
raises
(
Exception
,
match
=
"
Missing ARKINDEX_CORPUS_ID environment variable
"
):
mock_elements_worker_read_only
.
corpus_id
def
test_corpus_id_set_read_only_mode
(
monkeypatch
,
mock_elements_worker_read_only
:
ElementsWorker
):
corpus_id
=
str
(
uuid
.
uuid4
())
monkeypatch
.
setenv
(
"
ARKINDEX_CORPUS_ID
"
,
corpus_id
)
mock_elements_worker_read_only
.
configure
()
assert
mock_elements_worker_read_only
.
corpus_id
==
corpus_id
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