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
|
# new story instance on each run
|
||||||
port = self.command.config['web']['port']
|
port = self.command.config['web']['port']
|
||||||
|
|
||||||
|
resuming = False
|
||||||
if Story.hugveyHasSavedState(self.id):
|
if Story.hugveyHasSavedState(self.id):
|
||||||
self.logger.info(f"Recovering from state :-)")
|
self.logger.info(f"Recovering from state :-)")
|
||||||
self.story = Story.loadStoryFromState(self)
|
self.story = Story.loadStoryFromState(self)
|
||||||
|
resuming = True
|
||||||
if self.story.language_code != self.language_code:
|
if self.story.language_code != self.language_code:
|
||||||
self.logger.info("Changing language")
|
self.logger.info("Changing language")
|
||||||
self.configureLanguage(self.story.language_code)
|
self.configureLanguage(self.story.language_code)
|
||||||
|
@ -734,7 +736,7 @@ class HugveyState(object):
|
||||||
self.logger.info(f"Starting from {startMsgId}")
|
self.logger.info(f"Starting from {startMsgId}")
|
||||||
|
|
||||||
self.setLightStatus(False)
|
self.setLightStatus(False)
|
||||||
await self.story.run(startMsgId)
|
await self.story.run(startMsgId, resuming)
|
||||||
# self.story = None
|
# self.story = None
|
||||||
|
|
||||||
def getStreamer(self):
|
def getStreamer(self):
|
||||||
|
|
|
@ -1349,8 +1349,8 @@ class Story(object):
|
||||||
for direction in directions:
|
for direction in directions:
|
||||||
for condition in direction.conditions:
|
for condition in direction.conditions:
|
||||||
if condition.isMet(self):
|
if condition.isMet(self):
|
||||||
self.logger.info("Condition is met: {0}, going to {1}".format(
|
self.logger.info("Condition is met: {0} ({2}), going to {1}".format(
|
||||||
condition.id, direction.msgTo.id))
|
condition.id, direction.msgTo.id, condition.type))
|
||||||
self.hugvey.eventLogger.info("condition: {0}".format(condition.id))
|
self.hugvey.eventLogger.info("condition: {0}".format(condition.id))
|
||||||
self.hugvey.eventLogger.info("direction: {0}".format(direction.id))
|
self.hugvey.eventLogger.info("direction: {0}".format(direction.id))
|
||||||
metCondition = condition
|
metCondition = condition
|
||||||
|
@ -1463,17 +1463,20 @@ class Story(object):
|
||||||
for i in range(len(self.events)):
|
for i in range(len(self.events)):
|
||||||
await self._processPendingEvents()
|
await self._processPendingEvents()
|
||||||
|
|
||||||
# Test stability of Central Command with deliberate crash
|
|
||||||
# if self.timer.getElapsed() > 10:
|
|
||||||
# raise Exception("Test exception")
|
|
||||||
|
|
||||||
|
|
||||||
directions = self.getCurrentDirections()
|
directions = self.getCurrentDirections()
|
||||||
await self._processDirections(directions)
|
await self._processDirections(directions)
|
||||||
|
|
||||||
# TODO create timer event
|
# TODO create timer event
|
||||||
# self.commands.append({'msg':'TEST!'})
|
# 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
|
# wait for next iteration to avoid too high CPU
|
||||||
t = time.time()
|
t = time.time()
|
||||||
await asyncio.sleep(max(0, loopDuration - (t - lastTime)))
|
await asyncio.sleep(max(0, loopDuration - (t - lastTime)))
|
||||||
|
@ -1582,16 +1585,23 @@ class Story(object):
|
||||||
# none found
|
# none found
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def run(self, customStartMsgId = None):
|
async def run(self, customStartMsgId = None, resuming = False):
|
||||||
self.logger.info("Starting story")
|
self.logger.info("Starting story")
|
||||||
self.hugvey.eventLogger.info("story: start")
|
if not resuming:
|
||||||
self.timer.reset()
|
self.hugvey.eventLogger.info("story: start")
|
||||||
self.isRunning = True
|
self.timer.reset()
|
||||||
if customStartMsgId is not None:
|
self.isRunning = True
|
||||||
startMsg = self.get(customStartMsgId)
|
if customStartMsgId is not None:
|
||||||
|
startMsg = self.get(customStartMsgId)
|
||||||
|
else:
|
||||||
|
startMsg = self.startMessage
|
||||||
|
await self.setCurrentMessage(startMsg)
|
||||||
else:
|
else:
|
||||||
startMsg = self.startMessage
|
self.hugvey.eventLogger.info(f"story: resume from {self.currentMessage}")
|
||||||
await self.setCurrentMessage(startMsg)
|
self.isRunning = True
|
||||||
|
if not self.lastMsgFinishTime and self.currentMessage:
|
||||||
|
await self.setCurrentMessage(self.currentMessage)
|
||||||
|
|
||||||
await self._renderer()
|
await self._renderer()
|
||||||
|
|
||||||
def isFinished(self):
|
def isFinished(self):
|
||||||
|
|
|
@ -100,6 +100,12 @@ img.icon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
right: 5px; }
|
right: 5px; }
|
||||||
|
#status .hugvey .light {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 3px;
|
||||||
|
right: 3px; }
|
||||||
|
#status .hugvey .light input {
|
||||||
|
width: 2em; }
|
||||||
#status .hugvey .stats .count {
|
#status .hugvey .stats .count {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-right: 10px; }
|
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="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 == '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 == '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'>
|
<!-- <div class='light'>
|
||||||
{{ hv.light }}
|
{{ hv.light }}
|
||||||
</div> -->
|
</div> -->
|
||||||
|
|
|
@ -141,6 +141,16 @@ img.icon{
|
||||||
right: 5px;
|
right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.light{
|
||||||
|
position:absolute;
|
||||||
|
bottom: 3px;
|
||||||
|
right:3px;
|
||||||
|
input{
|
||||||
|
width: 3.2em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.stats{
|
.stats{
|
||||||
.count{
|
.count{
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
Loading…
Reference in a new issue