Skip to content

Commit

Permalink
Make the sleep times come from constants.py and settable via env vars. (
Browse files Browse the repository at this point in the history
#114)

* Make the sleep times come from constants.py and settable via env vars.

No-Issue

Signed-off-by: James Tanner <tanner.jc@gmail.com>

* Allow fractional seconds.

No-Issue

Signed-off-by: James Tanner <tanner.jc@gmail.com>

---------

Signed-off-by: James Tanner <tanner.jc@gmail.com>
  • Loading branch information
jctanner authored Jun 3, 2024
1 parent bfd637f commit 1d06632
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions galaxykit/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from . import collections
from . import roles
from . import __version__ as VERSION
from .constants import RBAC_VERSION, EE_ENDPOINTS_CHANGE_VERSION
from .constants import RBAC_VERSION, EE_ENDPOINTS_CHANGE_VERSION, SLEEP_SECONDS_ONETIME

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -336,7 +336,7 @@ def _retry_if_expired_gw_token(self, method, url, headers, *args, **kwargs):
if self.response.status_code < 400:
return self.response
logger.debug(f"Reloading token failed: {self.response.text}")
time.sleep(5)
time.sleep(SLEEP_SECONDS_ONETIME)
self.response.raise_for_status()

def _payload(self, method, path, body, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions galaxykit/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from orionutils.generator import build_collection
from .utils import wait_for_task, logger, GalaxyClientError, wait_for_url
from .constants import EE_ENDPOINTS_CHANGE_VERSION
from .constants import EE_ENDPOINTS_CHANGE_VERSION, SLEEP_SECONDS_POLLING


def collection_info(client, repository, namespace, collection_name, version):
Expand Down Expand Up @@ -276,7 +276,7 @@ def move_or_copy_collection(
client.get(dest_url)
ready = True
except GalaxyClientError:
sleep(1)
sleep(SLEEP_SECONDS_POLLING)
timeout = timeout - 1
if timeout < 0:
raise
Expand Down
7 changes: 7 additions & 0 deletions galaxykit/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import os


RBAC_VERSION = "4.6.0dev"
EE_ENDPOINTS_CHANGE_VERSION = "4.7.0dev"

SLEEP_SECONDS_POLLING = float(os.environ.get('GALAXYKIT_SLEEP_SECONDS_POLLING', 10))
SLEEP_SECONDS_ONETIME = float(os.environ.get('GALAXYKIT_SLEEP_SECONDS_ONETIME', 10))
POLLING_MAX_ATTEMPTS = int(os.environ.get('GALAXYKIT_POLLING_MAX_ATTEMPTS', 10))
16 changes: 14 additions & 2 deletions galaxykit/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from time import sleep
from .constants import SLEEP_SECONDS_POLLING
from .constants import POLLING_MAX_ATTEMPTS


def get_tasks(client, only_running=False):
Expand All @@ -14,7 +16,12 @@ def get_task(client, task_id):
return client.get(tasks_url)


def wait_task(client, task_id, sleep_seconds=10, max_attempts=10):
def wait_task(client, task_id, sleep_seconds=None, max_attempts=None):
if sleep_seconds is None:
sleep_seconds = SLEEP_SECONDS_POLLING
if max_attempts is None:
max_attempts = POLLING_MAX_ATTEMPTS

task = get_task(client, task_id)

while task["state"] not in ["completed", "failed", "canceled"]:
Expand All @@ -32,7 +39,12 @@ def wait_task(client, task_id, sleep_seconds=10, max_attempts=10):
return task


def wait_all(client, sleep_seconds=10, max_attempts=10):
def wait_all(client, sleep_seconds=None, max_attempts=10):
if sleep_seconds is None:
sleep_seconds = SLEEP_SECONDS_POLLING
if max_attempts is None:
max_attempts = POLLING_MAX_ATTEMPTS

tasks = get_tasks(client, only_running=True)

while tasks and tasks["results"]:
Expand Down

0 comments on commit 1d06632

Please sign in to comment.