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): ...@@ -166,9 +166,14 @@ class BaseWorker(object):
worker_run = self.request( worker_run = self.request(
"RetrieveWorkerRun", id=os.environ["ARKINDEX_WORKER_RUN_ID"] "RetrieveWorkerRun", id=os.environ["ARKINDEX_WORKER_RUN_ID"]
) )
self.user_configuration = worker_run.get("configuration") configuration_id = worker_run.get("configuration_id")
if self.user_configuration: if configuration_id:
logger.info("Loaded user configuration from WorkerRun") 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") task_id = os.environ.get("PONOS_TASK")
paths = None paths = None
......
...@@ -46,7 +46,7 @@ class MetaDataMixin(object): ...@@ -46,7 +46,7 @@ class MetaDataMixin(object):
"type": type.value, "type": type.value,
"name": name, "name": name,
"value": value, "value": value,
"entity": entity, "entity_id": entity,
"worker_version": self.worker_version_id, "worker_version": self.worker_version_id,
}, },
) )
......
...@@ -143,18 +143,24 @@ def test_configure_worker_run(mocker, monkeypatch, responses, mock_config_api): ...@@ -143,18 +143,24 @@ def test_configure_worker_run(mocker, monkeypatch, responses, mock_config_api):
worker = BaseWorker() worker = BaseWorker()
mocker.patch.object(sys, "argv", ["worker"]) mocker.patch.object(sys, "argv", ["worker"])
run_id = "aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" run_id = "aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
configuration_id = "bbbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
monkeypatch.setenv("ARKINDEX_WORKER_RUN_ID", run_id) monkeypatch.setenv("ARKINDEX_WORKER_RUN_ID", run_id)
responses.add( responses.add(
responses.GET, responses.GET,
f"http://testserver/api/v1/imports/workers/{run_id}/", 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() worker.configure()
assert worker.user_configuration == {"a": "b"} 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 mocker, monkeypatch, responses, mock_config_api
): ):
worker = BaseWorker() worker = BaseWorker()
...@@ -168,6 +174,29 @@ def test_configure_worker_run_missing_conf( ...@@ -168,6 +174,29 @@ def test_configure_worker_run_missing_conf(
) )
worker.configure() 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 assert worker.user_configuration is None
......
...@@ -192,7 +192,7 @@ def test_create_metadata(responses, mock_elements_worker): ...@@ -192,7 +192,7 @@ def test_create_metadata(responses, mock_elements_worker):
"type": "location", "type": "location",
"name": "Teklia", "name": "Teklia",
"value": "La Turbine, Grenoble 38000", "value": "La Turbine, Grenoble 38000",
"entity": None, "entity_id": None,
"worker_version": "12341234-1234-1234-1234-123412341234", "worker_version": "12341234-1234-1234-1234-123412341234",
} }
assert metadata_id == "12345678-1234-1234-1234-123456789123" assert metadata_id == "12345678-1234-1234-1234-123456789123"