From 74f6ae6e6a4a6d0bc5bf8a7932a86e0771dac03b Mon Sep 17 00:00:00 2001 From: Yoann Schneider <yschneider@teklia.com> Date: Thu, 23 Feb 2023 19:47:22 +0000 Subject: [PATCH] Add model version id as worker attribute --- arkindex_worker/worker/base.py | 6 ++++++ docs/contents/implem/configure.md | 3 +++ tests/test_base_worker.py | 1 + 3 files changed, 10 insertions(+) diff --git a/arkindex_worker/worker/base.py b/arkindex_worker/worker/base.py index beefdd6c..edb818a5 100644 --- a/arkindex_worker/worker/base.py +++ b/arkindex_worker/worker/base.py @@ -198,6 +198,9 @@ class BaseWorker(object): "'ARKINDEX_CORPUS_ID' was not set in the environment. Any API request involving a `corpus_id` will fail." ) + # Define model_version_id from environment + self.model_version_id = os.environ.get("ARKINDEX_MODEL_VERSION_ID") + # Load all required secrets self.secrets = {name: self.load_secret(name) for name in required_secrets} @@ -258,6 +261,9 @@ class BaseWorker(object): logger.info("Loaded model version configuration from WorkerRun") self.model_configuration.update(model_version.get("configuration")) + # Set model_version ID as worker attribute + self.model_version_id = model_version.get("id") + # if debug mode is set to true activate debug mode in logger if self.user_configuration.get("debug"): logger.setLevel(logging.DEBUG) diff --git a/docs/contents/implem/configure.md b/docs/contents/implem/configure.md index 37068608..59865d18 100644 --- a/docs/contents/implem/configure.md +++ b/docs/contents/implem/configure.md @@ -126,6 +126,9 @@ Many attributes are set on the worker during at the configuration stage. Here is `model_configuration` : The parsed configuration as stored in the `ModelVersion` object on Arkindex. +`model_version_id` +: The ID of the model version linked to the current `WorkerRun` object on Arkindex. You may set it in developer mode via the `ARKINDEX_MODEL_VERSION_ID` environment variable. + `process_information` : The details about the process parent to this worker execution. Only set in Arkindex mode. diff --git a/tests/test_base_worker.py b/tests/test_base_worker.py index e6f6457e..88edf67f 100644 --- a/tests/test_base_worker.py +++ b/tests/test_base_worker.py @@ -494,6 +494,7 @@ def test_configure_load_model_configuration(mocker, monkeypatch, responses): "param2": 2, "param3": None, } + assert worker.model_version_id == "12341234-1234-1234-1234-123412341234" def test_load_missing_secret(): -- GitLab