Skip to content

Commit

Permalink
Issue #163 EJR: only verify deletion
Browse files Browse the repository at this point in the history
creation should be covered by Open-EO/openeo-job-registry-elastic-api#20
  • Loading branch information
soxofaan committed Oct 4, 2023
1 parent c3b6101 commit f7c53bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
11 changes: 4 additions & 7 deletions openeo_driver/jobregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import time
import typing
from decimal import Decimal
from typing import Any, Dict, List, NamedTuple, Optional, Union
from typing import Any, Dict, List, NamedTuple, Optional, Union, Sequence

import requests
from openeo.rest.auth.oidc import OidcClientCredentialsAuthenticator, OidcClientInfo, OidcProviderInfo
Expand Down Expand Up @@ -235,8 +235,6 @@ def __init__(
self.set_user_agent()

self._debug_show_curl = _debug_show_curl
# TODO: expose this as constructor arg or even config?
self._verification_backoffs = [0, 0.1, 1.0]

def set_user_agent(self):
user_agent = f"openeo_driver-{openeo_driver._version.__version__}/{self.__class__.__name__}"
Expand Down Expand Up @@ -391,7 +389,6 @@ def create_job(
with self._with_extra_logging(job_id=job_id):
self.logger.info(f"EJR creating {job_id=} {created=}")
result = self._do_request("POST", "/jobs", json=job_data, expected_status=201)
self._verify_job_existence(job_id=job_id, exists=True)
return result

def get_job(self, job_id: str, fields: Optional[List[str]] = None) -> JobDict:
Expand Down Expand Up @@ -432,16 +429,16 @@ def delete_job(self, job_id: str) -> None:
raise e
self._verify_job_existence(job_id=job_id, exists=False)

def _verify_job_existence(self, job_id: str, exists: bool = True):
def _verify_job_existence(self, job_id: str, exists: bool = True, backoffs: Sequence[float] = (0, 0.1, 1.0)):
"""
Verify that EJR committed the job creation/deletion
:param job_id: job id
:param exists: whether the job should exist (after creation) or not exist (after deletion)
:return:
"""
if not self._verification_backoffs:
if not backoffs:
return
for backoff in self._verification_backoffs:
for backoff in backoffs:
self.logger.debug(f"_verify_job_existence {job_id=} {exists=} {backoff=}")
time.sleep(backoff)
try:
Expand Down
1 change: 0 additions & 1 deletion tests/test_jobregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ def test_job_id_logging(self, requests_mock, oidc_mock, ejr, caplog):
"""Check that job_id logging is passed through as logging extra in appropriate places"""
caplog.set_level(logging.DEBUG)


job_id = "j-123"

def post_jobs(request, context):
Expand Down

0 comments on commit f7c53bb

Please sign in to comment.