Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Nov 29, 2024
1 parent fb2033d commit 31e1a3e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
8 changes: 5 additions & 3 deletions pioreactor/background_jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
6 changes: 3 additions & 3 deletions pioreactor/background_jobs/stirring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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


Expand Down
33 changes: 19 additions & 14 deletions pioreactor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(?)"
Expand Down

0 comments on commit 31e1a3e

Please sign in to comment.