abc-messenger/message.py
Andrew Gundersen 5b54f3f636 working v1
2020-11-21 14:43:17 -06:00

37 lines
No EOL
849 B
Python

# messenge.py
import asyncio
import mailroom
# Independent loop that updates mailboxes.
async def messenger():
print("Running Messenger")
while True:
# Yield if no mailboxes.
if mailroom.que.empty():
await asyncio.sleep(1)
continue
# Grab a mailbox.
mailbox = mailroom.que.get()
print(f"Handling mailbox: {mailbox.name}.")
# Handle every message in outbox.
while not mailbox.outbox.empty():
message = mailbox.outbox.get()
# Get mailbox of target and put mail there.
target_mailbox = mailroom.get_mailbox(message.target)
await target_mailbox.inbox.put(message)
# Put the mailbox back
mailroom.que.put(mailbox)
await asyncio.sleep(1)
async def run():
await messenger()