Add logbuffer for file, don't save state on initial message, client should now continue after a fetch file crash

This commit is contained in:
Ruben van de Ven 2019-11-14 20:17:28 +01:00
parent 14d1e8c8ce
commit 1501b9f820
3 changed files with 90 additions and 80 deletions

View File

@ -191,9 +191,9 @@ class CentralCommand(object):
diffs = diff.total_seconds()
if diffs > 900:
# evLogger.warning("Very long time since audience spoke")
status['time_since_visitor_spoke'] = 'critical'
status['time_since_visitor_spoke_state'] = 'critical'
elif diffs > 1800:
status['time_since_visitor_spoke'] = 'warning'
status['time_since_visitor_spoke_state'] = 'warning'
# else:
# #clear warning
# pass

View File

@ -294,6 +294,7 @@ class CommandHandler(object):
duration = cmd['duration'] if 'duration' in cmd else None
self.playingMsgId = msgId
try:
if self.playPopen:
logger.info("Interrupting playback of {}".format(self.playingMsgId))
self.playPopen.kill()
@ -370,6 +371,10 @@ class CommandHandler(object):
logger.critical("Had returncode {} on play: {}\n\n{}\n{}".format(returnCode, playCmd, out, err))
else:
logger.debug("Finished playback.")
except Exception as e:
# sometimes playback gives a timeout, then a playbackFinish still needs to be send to inform the server to continue
logger.critical("Exception during playing of message")
logger.exception(e)
self.playingMsgId = None
self.muteMic = False

View File

@ -1317,6 +1317,7 @@ class Story(object):
self.variables = {}
self.variableValues = {} # captured variables from replies
self.runId = uuid.uuid4().hex
self.currentLightPresetNr = None
def pause(self):
self.logger.debug('pause hugvey')
@ -1810,8 +1811,6 @@ class Story(object):
message.id, message.getText()))
if message.id != self.startMessage.id:
self.addToLog(message)
else:
self.logger.debug("Not counting start message")
self.hugvey.eventLogger.info(f"message: {message.id} {message.uuid} start \"{message.getText()}\"")
@ -1856,6 +1855,8 @@ class Story(object):
logmsg += "\n- {0} -> {1} (when: {2}) ".format(direction.msgFrom.id, direction.msgTo.id, conditions)
self.logger.log(LOG_BS,logmsg)
if message.id != self.startMessage.id:
self.storeState()
def fadeLightPreset(self, presetNr: int):
@ -1864,6 +1865,7 @@ class Story(object):
return
preset = self.configuration.getLightPresets()[presetNr]
self.currentLightPresetNr = presetNr
self.hugvey.transitionLight(preset['intensity'], preset['fade'])
@ -2048,7 +2050,8 @@ class Story(object):
os.fsync(fp.fileno())
os.rename(tmpfn, fn)
self.logger.debug(f"saved state to {fn}")
duration = time.time() - self.stateSave
self.logger.debug(f"saved state to {fn} in {duration}s")
def hasSavedState(self):
return self.hugveyHasSavedState(self.hugvey.lightId)
@ -2067,7 +2070,9 @@ class Story(object):
#: :type story: Story
story.logger = mainLogger.getChild(f"{story.hugvey.id}").getChild("story")
# TODO: this is not really working because it is overridden by the set-status later.
story.hugvey.setLightStatus(story.lightStateSave)
# story.hugvey.setLightStatus(story.lightStateSave)
if story.currentLightPresetNr is not None:
story.fadeLightPreset(story.currentLightPresetNr)
return story
@classmethod