forked from MycroftAI/mycroft-core
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ovos-bus-client ovos-bus-client manage session in intent service not skill class get_response tied to session dont expire default session for backwards compat improve default session use existing SessionManager class use existing Session class use existing Session class message history simplify lazy manage history add ConverseSession feat/converse_session get active skill list from message.context
- Loading branch information
Showing
10 changed files
with
98 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1 @@ | ||
# Copyright 2017 Mycroft AI Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
import time | ||
from threading import Lock | ||
from uuid import uuid4 | ||
|
||
from ovos_config.config import Configuration | ||
from ovos_utils.log import LOG | ||
|
||
|
||
class Session: | ||
""" | ||
An class representing a Mycroft Session Identifier | ||
""" | ||
|
||
def __init__(self, session_id, expiration_seconds=180): | ||
self.session_id = session_id | ||
self.touch_time = int(time.time()) | ||
self.expiration_seconds = expiration_seconds | ||
|
||
def touch(self): | ||
""" | ||
update the touch_time on the session | ||
:return: | ||
""" | ||
self.touch_time = int(time.time()) | ||
|
||
def expired(self): | ||
""" | ||
determine if the session has expired | ||
:return: | ||
""" | ||
return int(time.time()) - self.touch_time > self.expiration_seconds | ||
|
||
def __str__(self): | ||
return "{%s,%d}" % (str(self.session_id), self.touch_time) | ||
|
||
|
||
class SessionManager: | ||
""" Keeps track of the current active session. """ | ||
__current_session = None | ||
__lock = Lock() | ||
|
||
@staticmethod | ||
def get(): | ||
""" | ||
get the active session. | ||
:return: An active session | ||
""" | ||
config = Configuration().get('session') | ||
|
||
with SessionManager.__lock: | ||
if (not SessionManager.__current_session or | ||
SessionManager.__current_session.expired()): | ||
SessionManager.__current_session = Session( | ||
str(uuid4()), expiration_seconds=config.get('ttl', 180)) | ||
LOG.info( | ||
"New Session Start: " + | ||
SessionManager.__current_session.session_id) | ||
return SessionManager.__current_session | ||
|
||
@staticmethod | ||
def touch(): | ||
""" | ||
Update the last_touch timestamp on the current session | ||
:return: None | ||
""" | ||
SessionManager.get().touch() | ||
from ovos_bus_client.session import Session, SessionManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.