Skip to content

Commit

Permalink
Fixes #31: preserve "usage" batch job metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Jan 18, 2022
1 parent 23bedfb commit a209af2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Preserve "job_options" field in batch job submit
- Preserve "usage" batch job metadata ([#31](https://github.com/Open-EO/openeo-aggregator/issues/31))



Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
install_requires=[
"requests",
"openeo>=0.9.2.a2.dev",
"openeo_driver>=0.14.13.dev",
"openeo_driver>=0.15.1.dev",
"flask~=2.0",
"gunicorn~=20.0",
"python-json-logger>=2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def get_user_jobs(self, user_id: str) -> Union[List[BatchJobMetadata], dict]:
backend_jobs = []
for job in backend_jobs:
job["id"] = JobIdMapping.get_aggregator_job_id(backend_job_id=job["id"], backend_id=con.id)
jobs.append(BatchJobMetadata.from_dict(job))
jobs.append(BatchJobMetadata.from_api_dict(job))

federation_missing.update(self.backends.get_disabled_connection_ids())
return dict_no_none({
Expand Down Expand Up @@ -511,7 +511,7 @@ def get_job_info(self, job_id: str, user: User) -> BatchJobMetadata:
self._translate_job_errors(job_id=job_id):
metadata = con.job(backend_job_id).describe_job()
metadata["id"] = job_id
return BatchJobMetadata.from_dict(metadata)
return BatchJobMetadata.from_api_dict(metadata)

def start_job(self, job_id: str, user: 'User'):
con, backend_job_id = self._get_connection_and_backend_job_id(aggregator_job_id=job_id)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,11 @@ def test_get_job_metadata(self, api100, requests_mock, backend1):
"lc": {"process_id": "load_collection", "arguments": {"id": "S2"}, "result": True}
}},
"status": "running", "progress": 42, "created": "2017-01-01T09:32:12Z",
"usage": {
"cpu": {"value": 1000, "unit": "cpu-seconds"},
"memory": {"value": 2000, "unit": "mb-seconds"},
"duration": {"value": 3000, "unit": "seconds"},
},
})
api100.set_auth_bearer_token(token=TEST_USER_BEARER_TOKEN)
res = api100.get("/jobs/b1-th3j0b").assert_status_code(200)
Expand All @@ -821,6 +826,11 @@ def test_get_job_metadata(self, api100, requests_mock, backend1):
"lc": {"process_id": "load_collection", "arguments": {"id": "S2"}, "result": True}
}},
"status": "running", "progress": 42, "created": "2017-01-01T09:32:12Z",
"usage": {
"cpu": {"value": 1000, "unit": "cpu-seconds"},
"memory": {"value": 2000, "unit": "mb-seconds"},
"duration": {"value": 3000, "unit": "seconds"},
},
}

@pytest.mark.parametrize("job_id", ["th3j0b", "th-3j-0b", "th.3j.0b", "th~3j~0b"])
Expand Down

0 comments on commit a209af2

Please sign in to comment.