Skip to content
Snippets Groups Projects
Commit ec2c8462 authored by Yoann Schneider's avatar Yoann Schneider :tennis: Committed by Bastien Abadie
Browse files

Always setup api Client

parent d278157b
No related branches found
No related tags found
1 merge request!183Always setup api Client
Pipeline #79364 passed
......@@ -138,6 +138,9 @@ class ElementsWorker(
def configure(self):
# CLI args are stored on the instance so that implementations can access them
self.args = self.parser.parse_args()
super().setup_api_client()
if self.is_read_only:
super().configure_for_developers()
else:
......
......@@ -140,6 +140,11 @@ class BaseWorker(object):
or self.worker_run_id is None
)
def setup_api_client(self):
# Build Arkindex API client from environment variables
self.api_client = ArkindexClient(**options_from_env())
logger.debug(f"Setup Arkindex API client on {self.api_client.document.url}")
def configure_for_developers(self):
assert self.is_read_only
# Setup logging level if verbose or if ARKINDEX_DEBUG is set to true
......@@ -174,10 +179,6 @@ class BaseWorker(object):
logger.setLevel(logging.DEBUG)
logger.debug("Debug output enabled")
# Build Arkindex API client from environment variables
self.api_client = ArkindexClient(**options_from_env())
logger.debug(f"Setup Arkindex API client on {self.api_client.document.url}")
# Load worker run information
worker_run = self.request("RetrieveWorkerRun", id=self.worker_run_id)
......
......@@ -239,6 +239,7 @@ def mock_base_worker_with_cache(mocker, monkeypatch, mock_worker_run_api):
monkeypatch.setattr(sys, "argv", ["worker"])
worker = BaseWorker(support_cache=True)
worker.setup_api_client()
monkeypatch.setenv("PONOS_TASK", "my_task")
return worker
......
......@@ -98,6 +98,7 @@ def test_cli_default(mocker, mock_worker_run_api):
assert worker.worker_version_id == "12341234-1234-1234-1234-123412341234"
assert worker.worker_run_id == "56785678-5678-5678-5678-567856785678"
worker.setup_api_client()
worker.configure()
assert not worker.args.verbose
assert logger.level == logging.NOTSET
......@@ -118,6 +119,7 @@ def test_cli_arg_verbose_given(mocker, mock_worker_run_api):
assert worker.worker_version_id == "12341234-1234-1234-1234-123412341234"
assert worker.worker_run_id == "56785678-5678-5678-5678-567856785678"
worker.setup_api_client()
worker.configure()
assert worker.args.verbose
assert logger.level == logging.DEBUG
......@@ -139,6 +141,7 @@ def test_cli_envvar_debug_given(mocker, monkeypatch, mock_worker_run_api):
assert worker.worker_version_id == "12341234-1234-1234-1234-123412341234"
assert worker.worker_run_id == "56785678-5678-5678-5678-567856785678"
worker.setup_api_client()
worker.configure()
assert logger.level == logging.DEBUG
assert worker.api_client
......@@ -212,6 +215,7 @@ def test_configure_worker_run(mocker, monkeypatch, responses):
assert worker.worker_version_id == "12341234-1234-1234-1234-123412341234"
assert worker.worker_run_id == "56785678-5678-5678-5678-567856785678"
worker.setup_api_client()
worker.configure()
assert worker.user_configuration == {"a": "b"}
......@@ -270,6 +274,7 @@ def test_configure_user_configuration_defaults(
content_type="application/json",
)
worker.setup_api_client()
worker.configure()
assert worker.config == {"param_1": "/some/path/file.pth", "param_2": 12}
......@@ -323,6 +328,7 @@ def test_configure_user_config_debug(mocker, monkeypatch, responses, debug):
content_type="application/json",
)
worker.args = worker.parser.parse_args()
worker.setup_api_client()
worker.configure()
assert worker.user_configuration == {"debug": debug}
......@@ -370,6 +376,7 @@ def test_configure_worker_run_missing_conf(mocker, monkeypatch, responses):
content_type="application/json",
)
worker.args = worker.parser.parse_args()
worker.setup_api_client()
worker.configure()
assert worker.user_configuration is None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment