Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • workers/base-worker
1 result
Show changes
Commits on Source (2)
......@@ -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
......
......@@ -46,7 +46,7 @@ class MetaDataMixin(object):
"type": type.value,
"name": name,
"value": value,
"entity": entity,
"entity_id": entity,
"worker_version": self.worker_version_id,
},
)
......
......@@ -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
......
......@@ -192,7 +192,7 @@ def test_create_metadata(responses, mock_elements_worker):
"type": "location",
"name": "Teklia",
"value": "La Turbine, Grenoble 38000",
"entity": None,
"entity_id": None,
"worker_version": "12341234-1234-1234-1234-123412341234",
}
assert metadata_id == "12345678-1234-1234-1234-123456789123"