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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user