Skip to content

Commit

Permalink
fix exporting calibrations; don't restart huey in update scritps
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Oct 29, 2024
1 parent 494ac97 commit fa3cab3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pioreactor/actions/leader/backup_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pioreactor.whoami import UNIVERSAL_EXPERIMENT


def count_writes_occurring(unit: str) -> int:
def count_writes_occurring() -> int:
with local_intermittent_storage("mqtt_to_db_streaming") as c:
return c.get("inserts_in_last_60s", 0)

Expand Down Expand Up @@ -49,8 +49,8 @@ def backup_database(output_file: str, force: bool = False, backup_to_workers: in

logger.debug(f"Starting backup of database to {output_file}")

if not force and count_writes_occurring(unit) >= 2:
logger.debug("Too many writes to proceed with backup. Exiting.")
if not force and count_writes_occurring() >= 2:
logger.debug("Too many writes to proceed with backup. Exiting. Use --force to force backing up.")
return

current_time = current_utc_timestamp()
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/actions/leader/export_experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def export_experiment_data(
_partition_by_unit = True

if not _partition_by_unit:
if experiment is None or "experiment" not in get_column_names(cursor, table):
if experiment is None and "experiment" in get_column_names(cursor, table):
query = f"SELECT {timestamp_to_localtimestamp_clause} * from {table} ORDER BY {order_by}"
cursor.execute(query)
filename = f"{table}-{time}.csv"
Expand All @@ -115,7 +115,7 @@ def export_experiment_data(
os.remove(path_to_file)

else:
if experiment is not None or "experiment" not in get_column_names(cursor, table):
if experiment is not None and "experiment" in get_column_names(cursor, table):
query = f"SELECT {timestamp_to_localtimestamp_clause} * from {table} WHERE experiment=:experiment ORDER BY :order_by"
cursor.execute(query, {"experiment": experiment, "order_by": order_by})
else:
Expand Down
8 changes: 4 additions & 4 deletions pioreactor/actions/od_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,13 @@ def publish_to_leader(name: str) -> bool:

try:
res = put_into_leader("/api/calibrations", json=calibration_result)
if not res.ok:
success = False
res.raise_for_status()
echo("✅ Published to leader.")
except Exception as e:
print(e)
success = False
if not success:
print(e)
echo(f"Could not update in database on leader at http://{leader_address}/api/calibrations ❌")

return success


Expand Down
6 changes: 4 additions & 2 deletions pioreactor/actions/pump_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,12 @@ def publish_to_leader(name: str) -> bool:
try:
res = put_into_leader("/api/calibrations", json=calibration_result)
res.raise_for_status()
except Exception:
echo("✅ Published to leader.")
except Exception as e:
success = False
if not success:
print(e)
echo(f"❌ Could not publish on leader at http://{leader_address}/api/calibrations")

return success


Expand Down
21 changes: 21 additions & 0 deletions pioreactor/tests/test_update_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,24 @@ def test_pio_commands() -> None:
)

assert not error_msgs, "\n".join(error_msgs)


def test_no_restarting_huey_service() -> None:
# this can mess with updating if we interrupt huey.
script_directory = "update_scripts"
scripts = find_shell_scripts(script_directory)
error_msgs = []

for script in scripts:
with open(script, "r") as file:
for line_number, line in enumerate(file, start=1):
if line.lstrip().startswith("#"): # comment
continue

# Checking for 'systemctl restart huey'
if "systemctl restart huey" in line:
error_msgs.append(
f"Error in {script} at line {line_number}: 'systemctl restart huey' should not be used since it will halt updates."
)

assert not error_msgs, "\n".join(error_msgs)
2 changes: 1 addition & 1 deletion update_scripts/upcoming/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mv "$SCRIPT_DIR"/huey.service $HUEY_SERVICE_FILE

# Reload systemd to apply changes
sudo systemctl daemon-reload
sudo systemctl restart huey.service
#sudo systemctl restart huey.service # don't need to do this, a later ui update will.

sudo chown pioreactor:www-data /var/www/pioreactorui/__pycache__ || :
sudo chown pioreactor:www-data /var/www/pioreactorui/pioreactorui/__pycache__ || :
Expand Down

0 comments on commit fa3cab3

Please sign in to comment.