diff --git a/hugvey/central_command.py b/hugvey/central_command.py index d30b734..dc9a2d2 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -710,9 +710,11 @@ class HugveyState(object): # new story instance on each run port = self.command.config['web']['port'] + resuming = False if Story.hugveyHasSavedState(self.id): self.logger.info(f"Recovering from state :-)") self.story = Story.loadStoryFromState(self) + resuming = True if self.story.language_code != self.language_code: self.logger.info("Changing language") self.configureLanguage(self.story.language_code) @@ -734,7 +736,7 @@ class HugveyState(object): self.logger.info(f"Starting from {startMsgId}") self.setLightStatus(False) - await self.story.run(startMsgId) + await self.story.run(startMsgId, resuming) # self.story = None def getStreamer(self): diff --git a/hugvey/story.py b/hugvey/story.py index c4529d8..0eaca85 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -1349,8 +1349,8 @@ class Story(object): for direction in directions: for condition in direction.conditions: if condition.isMet(self): - self.logger.info("Condition is met: {0}, going to {1}".format( - condition.id, direction.msgTo.id)) + self.logger.info("Condition is met: {0} ({2}), going to {1}".format( + condition.id, direction.msgTo.id, condition.type)) self.hugvey.eventLogger.info("condition: {0}".format(condition.id)) self.hugvey.eventLogger.info("direction: {0}".format(direction.id)) metCondition = condition @@ -1463,16 +1463,19 @@ class Story(object): for i in range(len(self.events)): await self._processPendingEvents() -# Test stability of Central Command with deliberate crash -# if self.timer.getElapsed() > 10: -# raise Exception("Test exception") - - directions = self.getCurrentDirections() await self._processDirections(directions) # TODO create timer event # self.commands.append({'msg':'TEST!'}) + +# Test stability of Central Command with deliberate crash +# if self.timer.getElapsed() > 10: +# raise Exception("Test exception") + if not self.timer.hasMark('state_save') or self.timer.getElapsed('state_save') > 5: + self.storeState() + self.timer.setMark('state_save') + # wait for next iteration to avoid too high CPU t = time.time() @@ -1582,16 +1585,23 @@ class Story(object): # none found return None - async def run(self, customStartMsgId = None): + async def run(self, customStartMsgId = None, resuming = False): self.logger.info("Starting story") - self.hugvey.eventLogger.info("story: start") - self.timer.reset() - self.isRunning = True - if customStartMsgId is not None: - startMsg = self.get(customStartMsgId) + if not resuming: + self.hugvey.eventLogger.info("story: start") + self.timer.reset() + self.isRunning = True + if customStartMsgId is not None: + startMsg = self.get(customStartMsgId) + else: + startMsg = self.startMessage + await self.setCurrentMessage(startMsg) else: - startMsg = self.startMessage - await self.setCurrentMessage(startMsg) + self.hugvey.eventLogger.info(f"story: resume from {self.currentMessage}") + self.isRunning = True + if not self.lastMsgFinishTime and self.currentMessage: + await self.setCurrentMessage(self.currentMessage) + await self._renderer() def isFinished(self): diff --git a/www/css/styles.css b/www/css/styles.css index bb506f1..56919f7 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -100,6 +100,12 @@ img.icon { position: absolute; top: 10px; right: 5px; } + #status .hugvey .light { + position: absolute; + bottom: 3px; + right: 3px; } + #status .hugvey .light input { + width: 2em; } #status .hugvey .stats .count { display: inline-block; margin-right: 10px; } diff --git a/www/panopticon.html b/www/panopticon.html index 2655d9e..5d80ac6 100644 --- a/www/panopticon.html +++ b/www/panopticon.html @@ -64,6 +64,8 @@
Finish
Pause
Resume
+ +
Resume from save
diff --git a/www/scss/styles.scss b/www/scss/styles.scss index 278b7e6..f617858 100644 --- a/www/scss/styles.scss +++ b/www/scss/styles.scss @@ -141,6 +141,16 @@ img.icon{ right: 5px; } + + .light{ + position:absolute; + bottom: 3px; + right:3px; + input{ + width: 3.2em; + } + } + .stats{ .count{ display: inline-block;