Skip to content

Commit

Permalink
Reimplement emergency_shutdown()
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 11, 2024
1 parent 16200fd commit f39c2ba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Take AG darks during the pre-observing task.
* Add `retry_without_parking` option to the shutdown recipe.
* Emit events for dome opening and closing and report them as notifications.
* Modified `emergency_shutdown()` to close the dome if the shutdown recipe fails.

### 🔧 Fixed

Expand Down
1 change: 1 addition & 0 deletions src/gort/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class Event(UpperStrEnum):
DOME_OPEN = auto()
DOME_CLOSING = auto()
DOME_CLOSED = auto()
EMERGENCY_SHUTDOWN = auto()
UNCATEGORISED = auto()


Expand Down
28 changes: 22 additions & 6 deletions src/gort/gort.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
TypeVar,
)

from lvmopstools.retrier import Retrier
from packaging.version import Version
from rich import pretty, traceback
from rich.logging import RichHandler
Expand Down Expand Up @@ -675,15 +676,30 @@ async def notify_event(self, event: Event, payload: dict[str, Any] = {}):
)
await notify_event(event)

async def emergency_close(self):
@Retrier(max_attempts=3, delay=3)
async def emergency_shutdown(self):
"""Parks and closes the telescopes."""

tasks = []
tasks.append(self.telescopes.park(disable=True))
tasks.append(self.enclosure.close(force=True, retry_without_parking=True))
self.log.warning("Emergency shutdown initiated.")
await self.notify_event(Event.EMERGENCY_SHUTDOWN)

try:
await self.shutdown(
park_telescopes=True,
disable_overwatcher=True,
retry_without_parking=True,
show_message=False,
)

except Exception as err:
self.log.error(f"Failed to shutdown: {err!r}")
self.log.warning("Trying to just close the dome.")

self.log.warning("Closing and parking telescopes.")
await asyncio.gather(*tasks)
await self.enclosure.close(
park_telescopes=True,
force=True,
retry_without_parking=True,
)

async def observe(
self,
Expand Down
7 changes: 6 additions & 1 deletion src/gort/recipes/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ async def recipe(
additional_close: bool = False,
disable_overwatcher: bool = False,
retry_without_parking: bool = False,
show_message: bool = True,
):
"""Shutdown the telescope, closes the dome, etc.
Expand All @@ -164,6 +165,9 @@ async def recipe(
retry_without_parking
If the dome fails to park the telescopes before closing the dome, retries
without parking the telescopes.
show_message
If :obj:`True`, shows a message with instructions on how to confirm
the dome is closed.
"""

Expand Down Expand Up @@ -196,7 +200,8 @@ async def recipe(
await asyncio.sleep(5)
await self.gort.enclosure.close(force=True)

self.gort.log.warning(SHUTDOWN_MESSAGE)
if show_message:
self.gort.log.warning(SHUTDOWN_MESSAGE)


class CleanupRecipe(BaseRecipe):
Expand Down

0 comments on commit f39c2ba

Please sign in to comment.