Skip to content

Commit

Permalink
more clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jul 11, 2024
1 parent 85d2b78 commit 323a66a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 64 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
### Upcoming


#### Enhancements

- improvements to the UI's experiment profile preview. It's so pretty!
- UI chips everywhere!
- improvements to the UI's experiment profile preview.
- `hours_elapsed()` is a function in profile expressions, which returns the hours since the profile started.
- `unit()` can be used in mqtt fetch expressions. Example: `unit():stirring:target_rpm` is identical to `::stirring:target_rpm`. The latter can be seen as a shortened version of the former.
- experiment profiles can have a `description` in the `job` field (i.e. beside `actions`).
Expand Down
7 changes: 1 addition & 6 deletions pioreactor/background_jobs/temperature_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,7 @@ def _set_growth_rate(self, message: pt.MQTTMessage) -> None:
self.latest_growth_rate_at = payload.timestamp

def _set_latest_temperature(self, temperature: structs.Temperature) -> None:
# we want to avoid a flurry of temperature data coming in, i.e. after a network reconnect.
# naive solution: only allow temp data from within 5m
if (current_utc_datetime() - temperature.timestamp).total_seconds() >= 5 * 60:
self.logger.debug(f"Temperature data too old to execute on: {temperature}")
return

# Note: this doesn't use MQTT data (previously it use to)
self.previous_temperature = self.latest_temperature
self.latest_temperature = temperature.temperature
self.latest_temperature_at = temperature.timestamp
Expand Down
42 changes: 0 additions & 42 deletions pioreactor/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,6 @@ def _add(cls):
return t.Union[tuple(classes)] # type: ignore


class Automation(Struct):
"""
Used to change an automation over MQTT.
"""

automation_name: str
args: dict = {}

def __str__(self) -> str:
s = ""
s += f"{self.automation_name}"
s += "("
for i, (k, v) in enumerate(self.args.items()):
if k == "skip_first_run":
v = bool(int(v))
if i == 0:
s += f"{k}={v}"
else:
s += f", {k}={v}"

s += ")"
return s

def __repr__(self) -> str:
return str(self)


class TemperatureAutomation(Automation, tag="temperature"): # type: ignore
...


class DosingAutomation(Automation, tag="dosing"): # type: ignore
...


class LEDAutomation(Automation, tag="led"): # type: ignore
...


AnyAutomation = t.Union[LEDAutomation, TemperatureAutomation, DosingAutomation]


class AutomationSettings(Struct):
"""
Metadata produced when settings in an automation job change
Expand Down
14 changes: 5 additions & 9 deletions pioreactor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,36 +502,35 @@ def kill_jobs(self) -> int:

class MQTTKill:
def __init__(self) -> None:
self.list_of_job_names: list[str] = []
self.job_names_to_kill: list[str] = []

def append(self, name: str) -> None:
self.list_of_job_names.append(name)
self.job_names_to_kill.append(name)

def kill_jobs(self) -> int:
count = 0
if len(self.list_of_job_names) == 0:
if len(self.job_names_to_kill) == 0:
return count

from pioreactor.pubsub import create_client

with create_client() as client:
for i, name in enumerate(self.list_of_job_names):
for i, name in enumerate(self.job_names_to_kill):
count += 1
msg = client.publish(
f"pioreactor/{whoami.get_unit_name()}/{whoami.UNIVERSAL_EXPERIMENT}/{name}/$state/set",
"disconnected",
qos=1,
)

if (i + 1) == len(self.list_of_job_names):
if (i + 1) == len(self.job_names_to_kill):
# last one
msg.wait_for_publish(2)

return count


class JobManager:
AUTOMATION_JOBS = ("temperature_automation", "dosing_automation", "led_automation")
PUMPING_JOBS = (
"add_media",
"remove_waste",
Expand Down Expand Up @@ -634,9 +633,6 @@ def kill_jobs(self, all_jobs: bool = False, **query) -> int:
elif job == "led_intensity":
# led_intensity doesn't register with the JobManager, probably should somehow. #502
pass
elif job in self.AUTOMATION_JOBS:
# don't kill them, the parent will.
pass
else:
shell_kill.append(pid)
count += mqtt_kill.kill_jobs()
Expand Down
5 changes: 0 additions & 5 deletions pioreactor/utils/sqlite_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ def close(self) -> None:
# Check that the thread is done before returning.
self.join()

@property
def queue_size(self) -> int:
"""Return the queue size."""
return self._sql_queue.qsize()

def _query_results(self, token: str):
"""Get the query results for a specific token.
Expand Down

0 comments on commit 323a66a

Please sign in to comment.