Skip to content

Commit

Permalink
When testing for the celery beat schedule db, search all known
Browse files Browse the repository at this point in the history
extensions.
  • Loading branch information
natefoo committed Aug 25, 2022
1 parent dea82e3 commit 9042078
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion gravity/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"PYTHONPATH": "lib",
"GALAXY_CONFIG_FILE": "{galaxy_conf}",
}
CELERY_BEAT_DB_FILENAME = "celery-beat-schedule"


class GracefulMethod(enum.Enum):
Expand Down Expand Up @@ -117,7 +118,7 @@ class GalaxyCeleryBeatService(Service):
" --app galaxy.celery" \
" beat" \
" --loglevel {celery[loglevel]}" \
" --schedule {state_dir}/celery-beat-schedule"
" --schedule {state_dir}/" + CELERY_BEAT_DB_FILENAME


class GalaxyGxItProxyService(Service):
Expand Down
10 changes: 7 additions & 3 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
from yaml import safe_load

from gravity.cli import galaxyctl
from gravity.state import CELERY_BEAT_DB_FILENAME

STARTUP_TIMEOUT = 30
CELERY_BEAT_TIMEOUT = 10
# celery.beat.PersistentScheduler uses shelve, which can append a suffix based on which db backend is used
CELERY_BEAT_DB_FILENAMES = map(lambda ext: CELERY_BEAT_DB_FILENAME + ext, ('', '.db', '.dat', '.bak', '.dir'))


def test_cmd_register(state_dir, galaxy_yml):
Expand Down Expand Up @@ -52,10 +55,10 @@ def wait_for_gxit_proxy(state_dir):
return startup_logs


def wait_for_path(path, timeout):
def wait_for_any_path(paths, timeout):
for _ in range(timeout * 4):
try:
assert path.exists()
assert any(map(lambda x: x.exists(), paths))
return True
except AssertionError:
time.sleep(0.25)
Expand All @@ -80,7 +83,8 @@ def test_cmd_start(state_dir, galaxy_yml, startup_config, free_port):
assert result.exit_code == 0, result.output
start_instance(state_dir, free_port)
result = runner.invoke(galaxyctl, ['--state-dir', state_dir, 'status'])
celery_beat_db_exists = wait_for_path(state_dir / "celery-beat-schedule", CELERY_BEAT_TIMEOUT)
celery_beat_db_paths = map(lambda f: state_dir / f, CELERY_BEAT_DB_FILENAMES)
celery_beat_db_exists = wait_for_any_path(celery_beat_db_paths, CELERY_BEAT_TIMEOUT)
assert celery_beat_db_exists is True, "celery-beat failed to write db. State dir contents:\n" \
f"{os.listdir(state_dir)}"
result = runner.invoke(galaxyctl, ['--state-dir', state_dir, 'stop'])
Expand Down

0 comments on commit 9042078

Please sign in to comment.