From 31e1a3e45747e3d5318473bd8b6f1d2a22d21f57 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Thu, 28 Nov 2024 20:02:38 -0500 Subject: [PATCH] more --- pioreactor/background_jobs/base.py | 8 ++++--- pioreactor/background_jobs/stirring.py | 6 ++--- pioreactor/utils/__init__.py | 33 +++++++++++++++----------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/pioreactor/background_jobs/base.py b/pioreactor/background_jobs/base.py index a1771c29..02ae9bdc 100644 --- a/pioreactor/background_jobs/base.py +++ b/pioreactor/background_jobs/base.py @@ -1131,11 +1131,13 @@ def sneak_in(ads_interval, post_delay, pre_delay) -> None: self._action_to_do_before_od_reading() # this could fail in the following way: - # in the same experiment, the od_reading fails catastrophically so that the ADC attributes are never - # cleared. Later, this job starts, and it will pick up the _old_ ADC attributes. + # in the same experiment, the od_reading fails catastrophically so that the settings are never + # cleared. Later, this job starts, and it will pick up the _old_ settings. with JobManager() as jm: - ads_start_time = jm.get_setting_from_running_job("od_reading", "first_od_obs_time") ads_interval = jm.get_setting_from_running_job("od_reading", "interval") + ads_start_time = jm.get_setting_from_running_job( + "od_reading", "first_od_obs_time", block=True + ) # this is populated later in the job... # get interval, and confirm that the requirements are possible: post_delay + pre_delay <= ADS interval - (od reading duration) if not (ads_interval - self.OD_READING_DURATION > (post_delay + pre_delay)): diff --git a/pioreactor/background_jobs/stirring.py b/pioreactor/background_jobs/stirring.py index 8db9ec71..2c9eb79e 100644 --- a/pioreactor/background_jobs/stirring.py +++ b/pioreactor/background_jobs/stirring.py @@ -291,7 +291,8 @@ def action_to_do_after_od_reading(self): # self.poll_and_update_dc() def initialize_dodging_operation(self): - self.set_duty_cycle(0) # stop stirring + self._estimate_duty_cycle = 0 + self.set_duty_cycle(self._estimate_duty_cycle) self.rpm_check_repeated_thread = RepeatedTimer( 1_000, lambda *args: None, @@ -551,8 +552,7 @@ def start_stirring( experiment=experiment, rpm_calculator=rpm_calculator, ) - if not stirrer.currently_dodging_od: - stirrer.start_stirring() + stirrer.start_stirring() return stirrer diff --git a/pioreactor/utils/__init__.py b/pioreactor/utils/__init__.py index eee86104..ee0426b6 100644 --- a/pioreactor/utils/__init__.py +++ b/pioreactor/utils/__init__.py @@ -603,22 +603,27 @@ def upsert_setting(self, job_id: JobMetadataKey, setting: str, value: Any) -> No self.conn.commit() return - def get_setting_from_running_job(self, job_name: str, setting: str) -> Any: - if not self.is_job_running(job_name): + def get_setting_from_running_job(self, job_name: str, setting: str, block=False) -> Any: + if not block and not self.is_job_running(job_name): raise JobNotRunningError(f"Job {job_name} is not running.") - select_query = """ - SELECT value - FROM pio_job_published_settings s - JOIN pio_job_metadata m ON s.job_id = m.id - WHERE job_name=(?) and setting=(?) and is_running=1""" - self.cursor.execute(select_query, (job_name, setting)) - result = self.cursor.fetchone() # returns None if not found - if result is not None: - return result[0] - else: - # TODO: could also be that the setting was wrong... - raise NameError(f"Setting {setting} was not found.") + result = None + while result is None: + select_query = """ + SELECT value + FROM pio_job_published_settings s + JOIN pio_job_metadata m ON s.job_id = m.id + WHERE job_name=(?) and setting=(?) and is_running=1""" + self.cursor.execute(select_query, (job_name, setting)) + result = self.cursor.fetchone() # returns None if not found + + if result is not None: + return result[0] + else: + if block: + continue + else: + raise NameError(f"Setting {setting} was not found.") def set_not_running(self, job_id: JobMetadataKey) -> None: update_query = "UPDATE pio_job_metadata SET is_running=0, ended_at=STRFTIME('%Y-%m-%dT%H:%M:%f000Z', 'NOW') WHERE id=(?)"