From f7c53bbba644c0f86fa6e89a52112424930fef3a Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Tue, 3 Oct 2023 22:09:15 +0200 Subject: [PATCH] Issue #163 EJR: only verify deletion creation should be covered by https://github.com/Open-EO/openeo-job-registry-elastic-api/issues/20 --- openeo_driver/jobregistry.py | 11 ++++------- tests/test_jobregistry.py | 1 - 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/openeo_driver/jobregistry.py b/openeo_driver/jobregistry.py index c2a86491..50662bd7 100644 --- a/openeo_driver/jobregistry.py +++ b/openeo_driver/jobregistry.py @@ -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 @@ -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__}" @@ -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: @@ -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: diff --git a/tests/test_jobregistry.py b/tests/test_jobregistry.py index b6051c0b..15a57a00 100644 --- a/tests/test_jobregistry.py +++ b/tests/test_jobregistry.py @@ -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):