Skip to content

Commit

Permalink
if a user changes led intensity, we should _try_ to change it
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Nov 28, 2023
1 parent f52cbae commit b4373cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None:
options["unit"] = self.unit
options["experiment"] = whoami._get_latest_experiment_name() # techdebt
Thread(
target=led_intensity,
args=(state,),
target=utils.boolean_retry,
args=(led_intensity, state),
kwargs=options,
).start()

Expand Down
9 changes: 9 additions & 0 deletions pioreactor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
from pioreactor.pubsub import subscribe_and_callback


def boolean_retry(function: Callable, f_args, max_attempts: int = 3, sleep_for=0.25) -> bool:
for _ in range(max_attempts):
res = function(*f_args)
if res:
return res
time.sleep(sleep_for)
return False


class callable_stack:
"""
A class for managing a stack of callable objects in Python.
Expand Down

0 comments on commit b4373cd

Please sign in to comment.