Hugvey now resumes without replaying the last message
This commit is contained in:
parent
cb81c0616e
commit
81aeb6be27
5 changed files with 46 additions and 16 deletions
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -64,6 +64,8 @@
|
|||
<div class='btn' v-if="hv.status == 'running'" @click.stop="finish(hv)">Finish</div> <!-- to available state -->
|
||||
<div class='btn' v-if="hv.status == 'running'" @click.stop="pause(hv)">Pause</div>
|
||||
<div class='btn' v-if="hv.status == 'paused'" @click.stop="resume(hv)">Resume</div>
|
||||
|
||||
<div class='btn' v-if="(hv.status == 'available' || hv.status == 'blocked') && hv.has_state" @click.stop="resume(hv)">Resume from save</div>
|
||||
<!-- <div class='light'>
|
||||
{{ hv.light }}
|
||||
</div> -->
|
||||
|
|
|
@ -141,6 +141,16 @@ img.icon{
|
|||
right: 5px;
|
||||
}
|
||||
|
||||
|
||||
.light{
|
||||
position:absolute;
|
||||
bottom: 3px;
|
||||
right:3px;
|
||||
input{
|
||||
width: 3.2em;
|
||||
}
|
||||
}
|
||||
|
||||
.stats{
|
||||
.count{
|
||||
display: inline-block;
|
||||
|
|
Loading…
Reference in a new issue