Skip to content

Instantly share code, notes, and snippets.

@CamDavidsonPilon
Last active April 12, 2024 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CamDavidsonPilon/6f8de25c8c141504531f9c9a2e5bc31c to your computer and use it in GitHub Desktop.
Save CamDavidsonPilon/6f8de25c8c141504531f9c9a2e5bc31c to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x
set -e
export LC_ALL=C
PIO_DIR=/home/pioreactor/.pioreactor
# Get the hostname
HOSTNAME=$(hostname)
# Get the leader address
LEADER_HOSTNAME=$(crudini --get $PIO_DIR/config.ini cluster.topology leader_hostname)
DB_FILE=$(crudini --get $PIO_DIR/config.ini storage database)
if [ "$HOSTNAME" = "$LEADER_HOSTNAME" ]; then
# we've added the new database tables, let's populate them.
# 1. we add workers from the config to workers
if crudini --get $PIO_DIR/config.ini cluster.inventory &>/dev/null; then
units=$(crudini --get $PIO_DIR/config.ini cluster.inventory)
# Iterate over each unit and insert it into the database
while IFS= read -r unit; do
sqlite3 $DB_FILE "INSERT OR IGNORE INTO workers (pioreactor_unit, added_at, is_active) VALUES ('$unit', STRFTIME('%Y-%m-%dT%H:%M:%f000Z', 'NOW'), 1);"
done <<< "$units"
# 2. we assign the workers to the current experiment
sqlite3 $DB_FILE "INSERT INTO experiment_worker_assignments (pioreactor_unit, experiment, assigned_at) SELECT pioreactor_unit, experiment, added_at FROM workers JOIN latest_experiment;"
else
echo "No units defined in cluster.inventory"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment