Skip to content

Commit

Permalink
Full implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed May 29, 2024
1 parent b2520de commit 46dc7eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
28 changes: 23 additions & 5 deletions src/hal/actor/commands/abort_exposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

from __future__ import annotations

import asyncio

from typing import TYPE_CHECKING

from . import hal_command_parser


if TYPE_CHECKING:

from .. import HALCommandType
from hal.actor import HALCommandType
from hal.macros.expose import ExposeMacro


__all__ = ["abort_exposures"]
Expand All @@ -25,12 +27,28 @@
async def abort_exposures(command: HALCommandType):
"""Aborts ongoing exposures.."""

if command.actor.observatory == "APO":
return command.fail("abort-exposures is not supported for APO.")
expose_macro = command.actor.helpers.macros["expose"]
assert isinstance(expose_macro, ExposeMacro)

Check warning on line 31 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L30-L31

Added lines #L30 - L31 were not covered by tests

if expose_macro.running:
command.warning("Cancelling the expose macro.")
expose_macro.cancel(now=True)

Check warning on line 35 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L34-L35

Added lines #L34 - L35 were not covered by tests

command.warning("Aborting ongoing exposures.")

Check warning on line 37 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L37

Added line #L37 was not covered by tests

tasks = [

Check warning on line 39 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L39

Added line #L39 was not covered by tests
command.actor.helpers.apogee.abort(command),
command.actor.helpers.boss.abort(command),
]

return command.finish()
results = await asyncio.gather(*tasks, return_exceptions=True)

Check warning on line 44 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L44

Added line #L44 was not covered by tests
for iresult, result in enumerate(results):
instrument = ["APOGEE", "BOSS"][iresult]

Check warning on line 46 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L46

Added line #L46 was not covered by tests
if isinstance(result, Exception):
return command.fail(f"Failed to abort {instrument} exposure: {result!s}")

Check warning on line 48 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L48

Added line #L48 was not covered by tests
elif result is not True:
return command.fail(f"Unkown error while aborting {instrument} exposure.")

Check warning on line 50 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L50

Added line #L50 was not covered by tests
else:
continue

Check warning on line 52 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L52

Added line #L52 was not covered by tests

return command.finish(text="Exposures have been aborted.")

Check warning on line 54 in src/hal/actor/commands/abort_exposures.py

View check run for this annotation

Codecov / codecov/patch

src/hal/actor/commands/abort_exposures.py#L54

Added line #L54 was not covered by tests
2 changes: 2 additions & 0 deletions src/hal/helpers/apogee.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ async def abort(self, command: HALCommandType):

await self._send_command(command, "apogee", "stop", time_limit=60)

Check warning on line 312 in src/hal/helpers/apogee.py

View check run for this annotation

Codecov / codecov/patch

src/hal/helpers/apogee.py#L312

Added line #L312 was not covered by tests

return True

Check warning on line 314 in src/hal/helpers/apogee.py

View check run for this annotation

Codecov / codecov/patch

src/hal/helpers/apogee.py#L314

Added line #L314 was not covered by tests


class APOGEEGangHelper:
"""Helper for the APOGEE gang connector."""
Expand Down
12 changes: 8 additions & 4 deletions src/hal/helpers/boss.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,14 @@ async def readout(self, command: HALCommandType):
async def abort(self, command: HALCommandType):
"""Aborts the ongoing exposure."""

if not self.actor.observatory == "LCO":
raise ValueError("abort is not supported at APO.")

if not self.is_exposing():
command.warning("No exposure to abort.")
return True

Check warning on line 257 in src/hal/helpers/boss.py

View check run for this annotation

Codecov / codecov/patch

src/hal/helpers/boss.py#L256-L257

Added lines #L256 - L257 were not covered by tests

await self._send_command(command, "apogee", "abort", time_limit=60)
if self.actor.observatory == "LCO":
await self._send_command(command, "yao", "abort --reset", time_limit=60)

Check warning on line 260 in src/hal/helpers/boss.py

View check run for this annotation

Codecov / codecov/patch

src/hal/helpers/boss.py#L260

Added line #L260 was not covered by tests
else:
await self._send_command(command, "boss", "abort", time_limit=60)
await self._send_command(command, "boss", "clearExposure", time_limit=30)

Check warning on line 263 in src/hal/helpers/boss.py

View check run for this annotation

Codecov / codecov/patch

src/hal/helpers/boss.py#L262-L263

Added lines #L262 - L263 were not covered by tests

return True

Check warning on line 265 in src/hal/helpers/boss.py

View check run for this annotation

Codecov / codecov/patch

src/hal/helpers/boss.py#L265

Added line #L265 was not covered by tests

0 comments on commit 46dc7eb

Please sign in to comment.