Added abort to command
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
203b513c9e
commit
964a072e80
@ -8,6 +8,10 @@ class AbstractCommand(ABC):
|
||||
def execute(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def abort(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def describe(self) -> dict:
|
||||
pass
|
||||
|
@ -2,7 +2,7 @@ from typing import Dict
|
||||
|
||||
from .abstract_plugin import AbstractCommand, AbstractPlugin, AbstractCommandCompiler
|
||||
import logging
|
||||
import time
|
||||
from threading import Event
|
||||
|
||||
|
||||
class SleepCommand(AbstractCommand):
|
||||
@ -17,12 +17,20 @@ class SleepCommand(AbstractCommand):
|
||||
|
||||
self._secs = secs
|
||||
self._logger = logger
|
||||
self._event = Event()
|
||||
|
||||
def execute(self):
|
||||
self._logger.debug(f"Sleeping for {self._secs} seconds")
|
||||
time.sleep(self._secs)
|
||||
self._event.clear()
|
||||
aborted = self._event.wait(timeout=self._secs)
|
||||
if aborted:
|
||||
self._logger.warning("Sleeping aborted externally!")
|
||||
else:
|
||||
self._logger.debug(f"Slept for {self._secs} seconds")
|
||||
|
||||
def abort(self):
|
||||
self._event.set() # <- force the event.wait to return
|
||||
|
||||
def describe(self) -> dict:
|
||||
return {
|
||||
"command": "sleep",
|
||||
|
@ -29,6 +29,10 @@ class SyncCommand(AbstractCommand):
|
||||
self._procsync_instance.sync(self._name, self._nodes, Config.SYNC_TIMEOUT)
|
||||
self._logger.debug(f"Event {self._name} synchronized!")
|
||||
|
||||
def abort(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def describe(self) -> dict:
|
||||
return {
|
||||
"command": "sync",
|
||||
|
@ -33,7 +33,7 @@ class ProgramExecutor(Thread):
|
||||
|
||||
def abort(self):
|
||||
self._state = ProgramExecutorStates.ABORTED
|
||||
# TODO: implement abort
|
||||
self._program[self._pc].abort()
|
||||
|
||||
def get_status(self) -> dict:
|
||||
return {
|
||||
@ -55,7 +55,7 @@ class ProgramExecutor(Thread):
|
||||
self._state = ProgramExecutorStates.RUNNING
|
||||
self._logger.info("Start running program")
|
||||
|
||||
while True: # needed for loop
|
||||
while self._state == ProgramExecutorStates.RUNNING: # needed for loop
|
||||
self._loop_counter += 1
|
||||
for i, step in enumerate(self._program):
|
||||
self._pc = i
|
||||
@ -69,12 +69,13 @@ class ProgramExecutor(Thread):
|
||||
self._state = ProgramExecutorStates.CRASHED
|
||||
return
|
||||
|
||||
# TODO: jogging wait
|
||||
if self._state != ProgramExecutorStates.RUNNING:
|
||||
self._logger.info(f"State changed to {self._state.name}. Execution will now stop!")
|
||||
return
|
||||
|
||||
if self._loop:
|
||||
self._logger.debug("Looping program")
|
||||
else:
|
||||
self._logger.debug("Program ended")
|
||||
break
|
||||
|
||||
self._logger.info("Program ended")
|
||||
self._state = ProgramExecutorStates.DONE
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user