minor improvments
This commit is contained in:
parent
2287ddd6f1
commit
db2e6c4f15
14 changed files with 39 additions and 120 deletions
19
session.py
19
session.py
|
|
@ -6,39 +6,38 @@ import websockets
|
|||
|
||||
import mail
|
||||
import agent
|
||||
import schemes
|
||||
|
||||
|
||||
class Session(schemes.Schemes, agent.Agent, mail.Mail):
|
||||
class Session(agent.Agent, mail.Mail):
|
||||
"""Launch instance for every client connection.
|
||||
|
||||
Will recv messages from client and push them to mailbox.
|
||||
Also, will pull messages from mailbox and send to client.
|
||||
|
||||
"""
|
||||
def __init__(self, connection):
|
||||
def __init__(self, connection, crimata_id):
|
||||
mail.Mail.__init__(self, crimata_id)
|
||||
agent.Agent.__init__(self, connection)
|
||||
mail.Mail.__init__(self)
|
||||
|
||||
self.on = True
|
||||
|
||||
print("Launched sesssion.")
|
||||
print(f"Launched sesssion for {crimata_id}.")
|
||||
|
||||
# Recv intents run desired endpoint.
|
||||
async def do_agent_intents(self):
|
||||
while self.on:
|
||||
|
||||
try:
|
||||
intent = await asyncio.wait_for(
|
||||
jpackage = await asyncio.wait_for(
|
||||
self.recv_agent_intent(), timeout=0.2)
|
||||
except asyncio.TimeoutError:
|
||||
continue
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
await self.shutdown()
|
||||
continue
|
||||
continue
|
||||
|
||||
# Call corresponding endpoint.
|
||||
self.handle_intent(intent)
|
||||
self.mailbox_send(jpackage)
|
||||
|
||||
# Send mail back to agent.
|
||||
#! Pulling message from backend.
|
||||
|
|
@ -51,14 +50,14 @@ class Session(schemes.Schemes, agent.Agent, mail.Mail):
|
|||
|
||||
# Try recv.
|
||||
try:
|
||||
intent = await asyncio.wait_for(
|
||||
jpackage = await asyncio.wait_for(
|
||||
self.mailbox_recv(), timeout=0.2)
|
||||
except asyncio.TimeoutError:
|
||||
continue
|
||||
|
||||
# Send message to Agent.
|
||||
print("Sending message")
|
||||
await self.send_agent_intent(intent)
|
||||
await self.send_agent_intent(jpackage)
|
||||
|
||||
# Shutdown protocol.
|
||||
async def shutdown(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue