Skip to content

Commit

Permalink
pio kill --all-jobs should kill pumps too
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Nov 16, 2022
1 parent a0da3de commit 48894f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
34 changes: 29 additions & 5 deletions pioreactor/cli/pio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"""
cmd line interface for running individual pioreactor units (including leader)
> pio run od_reading
> pio run stirring --ignore-rpm
> pio log
> pio logs
"""
from __future__ import annotations

Expand Down Expand Up @@ -167,7 +166,15 @@ def led_off() -> None:
@click.option("--all-jobs", is_flag=True, help="kill all Pioreactor jobs running")
def kill(job: list[str], all_jobs: bool) -> None:
"""
stop a job by sending a SIGTERM to it.
stop a job(s).
"""
"""
This isn't a very clean way to end jobs (generally: actions). Ex: If a python script is running with Pioreactor jobs
running in it, it won't get closed.
Another approach is to iterate through /tmp/jon_metadata_*.db and fire an MQTT event to kill them. This would fail though if
not connected to leader...
"""

from sh import pkill # type: ignore
Expand All @@ -180,8 +187,25 @@ def safe_pkill(*args: str) -> None:
pass

if all_jobs:
# kill all running pioreactor processes
safe_pkill("-f", "pio run ")
sleep(1)

# kill all pumping
pubsub.publish(
f"pioreactor/{whoami.UNIVERSAL_IDENTIFIER}/{whoami.UNIVERSAL_EXPERIMENT}/add_media/$state/set",
"disconnected",
)
pubsub.publish(
f"pioreactor/{whoami.UNIVERSAL_IDENTIFIER}/{whoami.UNIVERSAL_EXPERIMENT}/remove_waste/$state/set",
"disconnected",
)
pubsub.publish(
f"pioreactor/{whoami.UNIVERSAL_IDENTIFIER}/{whoami.UNIVERSAL_EXPERIMENT}/add_alt_media/$state/set",
"disconnected",
)

# kill all LEDs
sleep(0.5)
led_intensity({"A": 0, "B": 0, "C": 0, "D": 0}, verbose=False)
else:
for j in job:
Expand Down Expand Up @@ -393,8 +417,8 @@ def update(ui: bool, app: bool, branch: Optional[str], source: Optional[str]) ->
run.add_command(jobs.led_control.click_led_control)
run.add_command(jobs.temperature_control.click_temperature_control)

run.add_command(actions.pump.click_add_alt_media)
run.add_command(actions.led_intensity.click_led_intensity)
run.add_command(actions.pump.click_add_alt_media)
run.add_command(actions.pump.click_add_media)
run.add_command(actions.pump.click_remove_waste)
run.add_command(actions.od_blank.click_od_blank)
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def append_signal_handlers(signal_value: signal.Signals, new_callbacks: list[Cal

class publish_ready_to_disconnected_state:
"""
Wrap a block of code to have "state" in MQTT. See od_normalization, self_test.
Wrap a block of code to have "state" in MQTT. See od_normalization, self_test, pump
You can use MQTT "/$state/set" tools to disconnect it.
You can use MQTT ".../$state/set" tools to disconnect it.
Example
----------
Expand Down

0 comments on commit 48894f6

Please sign in to comment.