Skip to content

Commit

Permalink
changed ScriptRunner so that it can be run multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
thusser committed Dec 24, 2023
1 parent 558f4a6 commit b6d2bfb
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions pyobs/modules/robotic/scriptrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
from typing import Any, Dict

from pyobs.modules import Module
from pyobs.interfaces import IAutonomous
from pyobs.interfaces import IRunnable
from pyobs.robotic.scripts import Script

log = logging.getLogger(__name__)


class ScriptRunner(Module, IAutonomous):
class ScriptRunner(Module, IRunnable):
"""Module for running a script."""

__module__ = "pyobs.modules.robotic"

def __init__(
self,
script: Dict[str, Any],
run_once: bool = False,
**kwargs: Any,
):
"""Initialize a new script runner.
Expand All @@ -27,29 +28,24 @@ def __init__(

# store
self.script = script
copy_comm = "comm" not in script.keys()
self._script = self.add_child_object(script, Script, copy_comm=copy_comm)
self._script = self.add_child_object(script, Script)

# add thread func
self.add_background_task(self._run_thread, False)
if run_once:
self.add_background_task(self._run_thread, False)

async def start(self, **kwargs: Any) -> None:
"""Starts a service."""
pass
async def run(self, **kwargs: Any) -> None:
"""Run script."""
script = self.get_object(self.script, Script)
await script.run(None)

async def stop(self, **kwargs: Any) -> None:
"""Stops a service."""
async def abort(self, **kwargs: Any) -> None:
"""Abort current actions."""
pass

async def is_running(self, **kwargs: Any) -> bool:
"""Whether a service is running."""
return True

async def _run_thread(self) -> None:
"""Run the script."""

# run script
await self._script.run(None)
await self.run()


__all__ = ["ScriptRunner"]

0 comments on commit b6d2bfb

Please sign in to comment.