Added abort to command
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-04-11 14:10:14 +02:00
parent 203b513c9e
commit 964a072e80
4 changed files with 27 additions and 10 deletions

View File

@@ -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 {