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:
@@ -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,11 +17,19 @@ 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._logger.debug(f"Slept for {self._secs} seconds")
|
||||
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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user