More Optim.

This commit is contained in:
2024-10-30 16:10:53 +01:00
parent 53bc4ac219
commit 01db00b3b4
13 changed files with 1454 additions and 886 deletions

View File

@ -144,7 +144,7 @@ class DB():
yield count['count']
else:
for row in self.db.execute(
"SELECT * FROM Messages {} ORDER BY time DESC LIMIT :lim OFFSET :off".format(where_clause),
"SELECT * FROM Messages {} ORDER BY time DESC, count DESC LIMIT :lim OFFSET :off".format(where_clause),
params
):
yield self._create_row_object(row, allow_lazy=True)

View File

@ -20,6 +20,7 @@ from ums.utils import AgentMessage, AgentResponse, logger
class MessageProcessor():
SOLUTION_MAX_TRIALS = int(os.environ.get('SOLUTION_MAX_TRIALS', 5))
MESSAGE_MAX_CONTACTS = int(os.environ.get('MESSAGE_MAX_CONTACTS', 100))
MANAGEMENT_URL = os.environ.get('MANAGEMENT_URL', 'http://127.0.0.1:80').strip().strip('/')
@ -78,6 +79,12 @@ class MessageProcessor():
# do not process processed messages again
return
# increment contacts counter
db_message.message.contacts += 1
if db_message.message.contacts > self.MESSAGE_MAX_CONTACTS:
logger.warning(f"Message reached max number of contacts! {db_message.message.id}, {count}")
return
# check which step/ state the message requires the management to do
if db_message.message.status.extract.required and not db_message.message.status.extract.finished:
# send to extract agents
@ -136,6 +143,9 @@ class MessageProcessor():
# add the riddle as new to management
self._send_message(self.MANAGEMENT_URL, message)
else:
logger.info(f"Unsolved riddle after max number of trials: {message.id}")
def _send_messages(self, recipients:List[str], message:AgentMessage) -> bool:
ok = True
for r in recipients: