diff --git a/arkindex_worker/worker/base.py b/arkindex_worker/worker/base.py index 1c76157cbf358d8440ed050603ce44ca8834ddef..320aed8c9f4d7af41ec8d95c0967e8dd06e28cbc 100644 --- a/arkindex_worker/worker/base.py +++ b/arkindex_worker/worker/base.py @@ -166,9 +166,14 @@ class BaseWorker(object): worker_run = self.request( "RetrieveWorkerRun", id=os.environ["ARKINDEX_WORKER_RUN_ID"] ) - self.user_configuration = worker_run.get("configuration") - if self.user_configuration: - logger.info("Loaded user configuration from WorkerRun") + configuration_id = worker_run.get("configuration_id") + if configuration_id: + worker_configuration = self.request( + "RetrieveWorkerConfiguration", id=configuration_id + ) + self.user_configuration = worker_configuration.get("configuration") + if self.user_configuration: + logger.info("Loaded user configuration from WorkerRun") task_id = os.environ.get("PONOS_TASK") paths = None diff --git a/tests/test_base_worker.py b/tests/test_base_worker.py index 4e8c3c0123ee27a58c44dc823079b74fd3c1e971..5d17d091cdd8a7db22a41f3a8fd53ecb731f710a 100644 --- a/tests/test_base_worker.py +++ b/tests/test_base_worker.py @@ -143,18 +143,24 @@ def test_configure_worker_run(mocker, monkeypatch, responses, mock_config_api): worker = BaseWorker() mocker.patch.object(sys, "argv", ["worker"]) run_id = "aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" + configuration_id = "bbbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" monkeypatch.setenv("ARKINDEX_WORKER_RUN_ID", run_id) responses.add( responses.GET, f"http://testserver/api/v1/imports/workers/{run_id}/", - json={"id": run_id, "configuration": {"a": "b"}}, + json={"id": run_id, "configuration_id": configuration_id}, + ) + responses.add( + responses.GET, + f"http://testserver/api/v1/workers/configurations/{configuration_id}/", + json={"id": configuration_id, "name": "BBB", "configuration": {"a": "b"}}, ) worker.configure() assert worker.user_configuration == {"a": "b"} -def test_configure_worker_run_missing_conf( +def test_configure_worker_run_missing_worker_conf( mocker, monkeypatch, responses, mock_config_api ): worker = BaseWorker() @@ -168,6 +174,29 @@ def test_configure_worker_run_missing_conf( ) worker.configure() + assert worker.user_configuration == {} + + +def test_configure_worker_run_missing_conf( + mocker, monkeypatch, responses, mock_config_api +): + worker = BaseWorker() + mocker.patch.object(sys, "argv", ["worker"]) + run_id = "aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" + configuration_id = "bbbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" + monkeypatch.setenv("ARKINDEX_WORKER_RUN_ID", run_id) + responses.add( + responses.GET, + f"http://testserver/api/v1/imports/workers/{run_id}/", + json={"id": run_id, "configuration_id": configuration_id}, + ) + responses.add( + responses.GET, + f"http://testserver/api/v1/workers/configurations/{configuration_id}/", + json={"id": configuration_id, "name": "BBB"}, + ) + worker.configure() + assert worker.user_configuration is None