Skip to content

Commit

Permalink
don't stall in monitor if network isn't found (that might be okay)
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Aug 7, 2024
1 parent 3a8e3ae commit 2573768
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#### Bug fixes

- more resilience to "UI state" diverging from "bioreactor state". Often, this occurred when two jobs stared almost immediately (often a networking issue), and the last job would halt since it couldn't get the required resources, however MQTT any data would be overwritten by the last job. Now, multiple places in the request pipeline will reduce duplication.
- more resilience to "UI state" diverging from "bioreactor state". Often, this occurred when two jobs stared almost immediately (often a networking issue), and the last job would halt since it couldn't get the required resources, however any MQTT data would be overwritten by the last job. Now, multiple places in the request pipeline will reduce duplication and prevent two jobs from starting too close to each other.
- Improved stirring clean up when stopped in quick succession after starting.
- if a network isn't found, the `monitor` job will not stall, but warning an continue.

#### Breaking changes

- in config.ini, the section `od_config` is now `od_reading.config`, and `stirring` is `stirring.config`. When you update, a script will run to automatically update these names in your config.inis.
- in config.ini, the section `od_config` renamed to `od_reading.config`, and `stirring` is `stirring.config`. When you update, a script will run to automatically update these names in your config.inis.

### 24.7.18

Expand Down
4 changes: 2 additions & 2 deletions config.dev.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ initial_volume_ml=14
initial_alt_media_fraction=0.0


[stirring]
[stirring.config]
target_rpm=500
initial_duty_cycle=15
pwm_hz=200
Expand All @@ -47,7 +47,7 @@ Kd=0.0
1=REF
2=90

[od_config]
[od_reading.config]
# how many samples should the ADC publish per second?
samples_per_second=0.2

Expand Down
21 changes: 15 additions & 6 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,23 @@ def check_for_network(self) -> None:
self.wlan_mac_address = "d8:3a:dd:61:01:59"
self.eth_mac_address = "d8:3a:dd:61:01:60"
else:
ipv4 = get_ip()
while ipv4 == "127.0.0.1" or ipv4 is None:
# no connection? Sound the alarm.
self.logger.warning("Unable to connect to network...")
self.flicker_led_with_error_code(error_codes.NO_NETWORK_CONNECTION)
sleep(1)

def did_find_network() -> bool:
ipv4 = get_ip()

if ipv4 == "127.0.0.1" or ipv4 is None:
# no connection? Sound the alarm.
self.logger.warning("Unable to find a network...")
self.flicker_led_with_error_code(error_codes.NO_NETWORK_CONNECTION)
return False
else:
return True

if utils.boolean_retry(did_find_network, retries=3, sleep_for=2):
ipv4: str = ""
else:
ipv4 = get_ip() or ""

self.ipv4 = ipv4

try:
Expand Down
8 changes: 7 additions & 1 deletion pioreactor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def invert_section(self, section: str) -> dict[str, str]:
return reversed_section

def _get_conv(self, section, option, conv, *, raw=False, vars=None, fallback=None, **kwargs):
return self._get(section, conv, option, raw=raw, vars=vars, fallback=fallback, **kwargs)
try:
return self._get(section, conv, option, raw=raw, vars=vars, fallback=fallback, **kwargs)
except TypeError as e:
from pioreactor.logging import create_logger

create_logger("read config").error(e)
raise e

def getboolean(self, section: str, option: str, *args, **kwargs) -> bool: # type: ignore
try:
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ def __getitem__(self, key: str) -> float:

def boolean_retry(
func: Callable[..., bool],
f_args: tuple,
f_kwargs: dict,
f_args: tuple = tuple(),
f_kwargs: dict = dict(),
retries: int = 3,
sleep_for: float = 0.25,
) -> bool:
Expand Down

0 comments on commit 2573768

Please sign in to comment.