ci: moved checks to separate file

This commit is contained in:
2024-11-19 21:48:23 +01:00
parent cda6265f64
commit a01778b67d
2 changed files with 52 additions and 7 deletions

View File

@ -15,13 +15,15 @@ services:
before_script:
# Check if ScyllaDB is ready (retry until successful)
- pip install ./backend
- |
echo "Waiting for ScyllaDB to be ready..."
until python -c "from cassandra.cluster import Cluster; cluster = Cluster(['scylla']); session = cluster.connect(); session.set_keyspace('test_bec_atlas');" 2>/dev/null; do
echo "ScyllaDB is not ready yet, retrying in 5 seconds..."
sleep 5
done
echo "ScyllaDB is up and running."
# - |
# echo "Waiting for ScyllaDB to be ready..."
# until python -c "from cassandra.cluster import Cluster; cluster = Cluster(['scylla']); session = cluster.connect(); session.set_keyspace('test_bec_atlas');" 2>/dev/null; do
# echo "ScyllaDB is not ready yet, retrying in 5 seconds..."
# sleep 5
# done
# echo "ScyllaDB is up and running."
- python ./backend/ci/healthchecks.py
test:
stage: test

View File

@ -0,0 +1,43 @@
import sys
import time
from cassandra.cluster import Cluster
SCYLLA_HOST = "scylla"
SCYLLA_KEYSPACE = "test_bec_atlas"
def wait_for_scylladb():
print("Waiting for ScyllaDB to be ready...")
while True:
try:
cluster = Cluster([SCYLLA_HOST])
session = cluster.connect()
session.set_keyspace(SCYLLA_KEYSPACE)
print("Connected to ScyllaDB")
break
except Exception as e:
print(f"ScyllaDB not ready yet: {e}")
time.sleep(5)
def create_keyspace():
print(f"Creating keyspace '{SCYLLA_KEYSPACE}' if not exists...")
try:
cluster = Cluster([SCYLLA_HOST])
session = cluster.connect()
session.execute(
f"""
CREATE KEYSPACE IF NOT EXISTS {SCYLLA_KEYSPACE}
WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': 1}}
"""
)
print(f"Keyspace '{SCYLLA_KEYSPACE}' created successfully.")
except Exception as e:
print(f"Failed to create keyspace: {e}")
sys.exit(1)
if __name__ == "__main__":
wait_for_scylladb()
create_keyspace()