Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions galaxykit/client.py
Original file line number Diff line number Diff line change
@@ -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__)

@@ -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):
4 changes: 2 additions & 2 deletions galaxykit/collections.py
Original file line number Diff line number Diff line change
@@ -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):
@@ -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
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):
@@ -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"]:
@@ -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"]: