-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from lsst-ts/tickets/DM-41082
Tickets/dm 41082
- Loading branch information
Showing
5 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Introduce the ``sleep.py`` script. This new addition allows users to sent a sleep command to the script queue for a desired duration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
# This file is part of ts_standardscripts | ||
# | ||
# Developed for the LSST Telescope and Site Systems. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import asyncio | ||
|
||
from lsst.ts.standardscripts import Sleep | ||
|
||
asyncio.run(Sleep.amain()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# This file is part of ts_standardscripts | ||
# | ||
# Developed for the LSST Telescope and Site Systems. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
__all__ = ["Sleep"] | ||
|
||
import asyncio | ||
|
||
import yaml | ||
from lsst.ts.salobj import BaseScript | ||
|
||
|
||
class Sleep(BaseScript): | ||
"""Sleep for a given amount of time. | ||
This script pauses the script queue for a specified amount of time. | ||
Parameters | ||
---------- | ||
index : `int` | ||
Index of Script SAL component. | ||
Notes | ||
----- | ||
**Details** | ||
This script sends a sleep command to the script queue, which pauses | ||
the script queue for a specified amount of time. | ||
""" | ||
|
||
def __init__(self, index): | ||
super().__init__(index=index, descr="Pause the script queue.") | ||
|
||
self.sleep_for = 0 | ||
|
||
@classmethod | ||
def get_schema(cls): | ||
schema_yaml = """ | ||
$schema: http://json-schema.org/draft-07/schema# | ||
$id: https://github.com/lsst-ts/ts_standardscripts/sleep.yaml | ||
title: Sleep v1 | ||
description: Configuration for Sleep command. | ||
type: object | ||
properties: | ||
sleep_for: | ||
description: >- | ||
Duration of the sleep command in seconds. | ||
type: number | ||
minimum: 0 | ||
additionalProperties: false | ||
""" | ||
return yaml.safe_load(schema_yaml) | ||
|
||
async def configure(self, config): | ||
"""Configure the script. | ||
Parameters | ||
---------- | ||
config : `types.SimpleNamespace` | ||
Configuration | ||
""" | ||
self.sleep_for = config.sleep_for | ||
|
||
def set_metadata(self, metadata): | ||
metadata.duration = self.sleep_for | ||
|
||
async def run(self): | ||
self.log.info(f"Sleep queue for {self.sleep_for} seconds...") | ||
await asyncio.sleep(self.sleep_for) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This file is part of ts_standardscripts | ||
# | ||
# Developed for the LSST Telescope and Site Systems. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import unittest | ||
|
||
from lsst.ts.standardscripts import BaseScriptTestCase, get_scripts_dir | ||
from lsst.ts.standardscripts.sleep import Sleep | ||
|
||
|
||
class TestSleep(BaseScriptTestCase, unittest.IsolatedAsyncioTestCase): | ||
async def basic_make_script(self, index): | ||
self.script = Sleep(index=index) | ||
return (self.script,) | ||
|
||
async def test_configure(self): | ||
# Test that the sleep time is set correctly | ||
async with self.make_script(): | ||
sleep_for = 5 | ||
|
||
await self.configure_script(sleep_for=sleep_for) | ||
|
||
self.assertEqual(self.script.sleep_for, sleep_for) | ||
|
||
async def test_run(self): | ||
""" | ||
Test that the script sleeps for the correct amount of time. | ||
""" | ||
async with self.make_script(): | ||
sleep_for = 5 | ||
await self.configure_script(sleep_for=sleep_for) | ||
|
||
# Run the script | ||
await self.run_script() | ||
|
||
async def test_executable(self): | ||
scripts_dir = get_scripts_dir() | ||
script_path = scripts_dir / "sleep.py" | ||
await self.check_executable(script_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |