diff --git a/README.md b/README.md index 69a22e5..5eb5c61 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,8 @@ for i in {1..26}; do echo $i;ssh pi@hugvey$i.local "cd hugvey && sudo bash insta To make sure it will not die with 'Too many files open' +examine open file limit with `ulimit -a` and set it with `ulimit -n NUMBER` + ```bash lsof -p $(ps aux|grep "[h]ugvey_server.py" |awk '{print $2}')| awk '{print $9}'|sort -rn|uniq -c|sort -rn|head -20 ``` diff --git a/hugvey/story.py b/hugvey/story.py index 326d291..4c0dd68 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -467,11 +467,11 @@ class Condition(object): return False number = int(self.vars['number']) - varValues = story.hugvey.command.variableStore.getLastOfName(self.vars['var_name'], number) + varValues = story.hugvey.command.variableStore.getLastOfName(self.vars['var_name'], story.language_code, number) self.hasRan = True if len(varValues) < number: - story.logger.critical(f"{self.id}: Too few instances of {self.vars['var_name']}, only {len(varValues)} in store") + story.logger.warn(f"{self.id}: Too few instances of {self.vars['var_name']}, only {len(varValues)} in store") return False for i in range(number): @@ -1277,7 +1277,7 @@ class Story(object): self.variableValues[name] = value if store: - self.hugvey.command.variableStore.addVariable(name, value, self.hugvey.id) + self.hugvey.command.variableStore.addVariable(name, value, self.hugvey.id, self.language_code) if name not in self.variables: return diff --git a/hugvey/variablestore.py b/hugvey/variablestore.py index b25e804..1f6c0c5 100644 --- a/hugvey/variablestore.py +++ b/hugvey/variablestore.py @@ -8,10 +8,11 @@ logger = mainLogger.getChild("variableStore") class Variable: - def __init__(self, name: str, value: str, hugveyId: int): + def __init__(self, name: str, value: str, hugveyId: int, languageCode: str): self.name = name self.value = value self.hugveyId = hugveyId + self.languageCode = languageCode class VariableStore: def __init__(self, db_filename): @@ -22,12 +23,14 @@ class VariableStore: CREATE TABLE IF NOT EXISTS `variables` ( `name` VARCHAR(255), `hugvey` INTEGER, + `language_code` VARCHAR(100), `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `val` VARCHAR(1024) ); """, """ CREATE INDEX IF NOT EXISTS `name_time` ON `variables` ( + `language_code`, `name`, `createdAt` DESC ); @@ -38,24 +41,24 @@ class VariableStore: self.conn.commit() self.q = asyncio.Queue() - def addVariable(self, name, value, hugveyId): - logger.debug(f"Queing storing of {name} for {hugveyId}") - self.q.put_nowait(Variable(name, value, hugveyId)) + def addVariable(self, name, value, hugveyId, languageCode): + logger.debug(f"Queing storing of {name} for {hugveyId} ({languageCode})") + self.q.put_nowait(Variable(name, value, hugveyId, languageCode)) async def queueProcessor(self): while True: #: :var v: Variable v = await self.q.get() c = self.conn.cursor() - logger.info(f"Store variable {v.name} for {v.hugveyId}: '{v.value}'") - c.execute("INSERT INTO variables (name, hugvey, createdAt, val) VALUES (?,?, current_timestamp,?)", (v.name, v.hugveyId, v.value)) + logger.info(f"Store variable {v.name} for {v.hugveyId} ({v.languageCode}): '{v.value}'") + c.execute("INSERT INTO variables (name, hugvey, language_code, createdAt, val) VALUES (?,?, ?, current_timestamp,?)", (v.name, v.hugveyId, v.languageCode, v.value)) self.conn.commit() c.close() - def getLastOfName(self, name, n = 10): + def getLastOfName(self, name, languageCode, n = 10): cur = self.conn.cursor() - logging.debug(f"Get last {n} stored variables of {name}") - cur.execute("SELECT val FROM variables WHERE name = ? ORDER BY createdAt DESC LIMIT ?", (name, n)) + logging.debug(f"Get last {n} stored variables of {name} for {languageCode}") + cur.execute("SELECT val FROM variables WHERE language_code = ? AND name = ? ORDER BY createdAt DESC LIMIT ?", (languageCode, name, n)) values = [v[0] for v in cur.fetchall()] cur.close() return values \ No newline at end of file