Skip to content

Commit

Permalink
small details'
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed May 3, 2023
1 parent 62e3cf2 commit 8ee8201
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
9 changes: 5 additions & 4 deletions pioreactor/actions/leader/backup_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def count_writes_occurring(unit: str) -> int:
return count


def backup_database(output_file: str) -> None:
def backup_database(output_file: str, force: bool = False) -> None:
"""
This action will create a backup of the SQLite3 database into specified output. It then
will try to copy the backup to any available worker Pioreactors as a further backup.
Expand All @@ -53,7 +53,7 @@ def backup_database(output_file: str) -> None:
"backup_database", experiment=experiment, unit=unit, to_mqtt=False
) # the backup would take so long that the mqtt client would disconnect. We also don't want to write to the db.

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

Expand Down Expand Up @@ -116,8 +116,9 @@ def backup_database(output_file: str) -> None:

@click.command(name="backup_database")
@click.option("--output", default="/home/pioreactor/.pioreactor/storage/pioreactor.sqlite.backup")
def click_backup_database(output: str) -> None:
@click.option("--force", is_flag=True, help="force backing up")
def click_backup_database(output: str, force: bool) -> None:
"""
(leader only) Backup db to workers.
"""
return backup_database(output)
return backup_database(output, force)
22 changes: 12 additions & 10 deletions pioreactor/background_jobs/leader/mqtt_to_db_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class TopicToParserToTable(Struct):
table: str


class TopicToCallback(Struct):
topic: str | list[str]
callback: Callable[[pt.MQTTMessage], None]


class MqttToDBStreamer(BackgroundJob):
topics_to_tables_from_plugins: list[TopicToParserToTable] = []
job_name = "mqtt_to_db_streaming"
Expand All @@ -72,13 +77,10 @@ def __init__(
topics_to_tables.extend(self.topics_to_tables_from_plugins)

topics_and_callbacks = [
{
"topic": topic_to_table.topic,
"callback": self.create_on_message_callback(
topic_to_table.parser, topic_to_table.table
),
"table": topic_to_table.table,
}
TopicToCallback(
topic_to_table.topic,
self.create_on_message_callback(topic_to_table.parser, topic_to_table.table),
)
for topic_to_table in topics_to_tables
]

Expand Down Expand Up @@ -140,11 +142,11 @@ def callback(message: pt.MQTTMessage) -> None:

return callback

def initialize_callbacks(self, topics_and_callbacks: list[dict]) -> None:
def initialize_callbacks(self, topics_and_callbacks: list[TopicToCallback]) -> None:
for topic_and_callback in topics_and_callbacks:
self.subscribe_and_callback(
topic_and_callback["callback"],
topic_and_callback["topic"],
topic_and_callback.callback,
topic_and_callback.topic,
qos=QOS.EXACTLY_ONCE,
allow_retained=False,
)
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def self_checks(self) -> None:
self.check_and_publish_self_statistics()

if whoami.am_I_leader():
sleep(10.0) # wait for other processes to catch up
self.check_for_last_backup()
sleep(10.0) # wait for other processes to catch up
self.check_for_required_jobs_running()
self.check_for_webserver()

Expand Down Expand Up @@ -399,7 +399,7 @@ def rpi_is_having_power_problems(self) -> bool:
def check_for_power_problems(self) -> None:
if self.rpi_is_having_power_problems():
self.logger.warning(
"Under-voltage detected. Suggestion: use a larger external power supply. See docs at: https://docs.pioreactor.com/user-guide/external-power"
"Under-voltage detected. Suggestion: use a better power supply or an AUX power. See docs at: https://docs.pioreactor.com/user-guide/external-power"
)
self.flicker_led_with_error_code(error_codes.VOLTAGE_PROBLEM)
else:
Expand Down

0 comments on commit 8ee8201

Please sign in to comment.