Configuration, launch and etc.
Configuration file of deploying unit, for shipped launcher (settings.py)
import sys
import logging
logging.basicConfig(format=(
'%(levelname)-8s [pid#%(process)d] %(asctime)s %(name)s '
'%(filename)s:%(lineno)d %(message)s'
), stream=sys.stdout, level=logging.DEBUG)
BUS = {
'redis': {
'backend': 'microagent.tools.redis.RedisSignalBus',
'dsn': 'redis://localhost/7',
'prefix': 'PREF',
},
}
BROKER = {
'redis': {
'backend': 'microagent.tools.redis.RedisBroker',
'dsn': 'redis://localhost/7',
},
}
AGENT = {
'user_agent': {
'backend': 'examples.user_agent.UserAgent',
'bus': 'redis',
'broker': 'redis',
},
'comment_agent': {
'backend': 'examples.comment_agent.CommentAgent',
'bus': 'redis',
'broker': 'redis',
},
'email_agent': {
'backend': 'examples.email_agent.EmailAgent',
'broker': 'redis',
},
}
Run in shell:
$ marun examples.settings
Custom server setup and starting (redis_server.py)
# mypy: ignore-errors
import sys
import asyncio
import logging
from microagent.tools.redis import RedisSignalBus, RedisBroker
from user_agent import UserAgent
from comment_agent import CommentAgent
from email_agent import EmailAgent
logging.basicConfig(format=(
'%(levelname)-8s [pid#%(process)d] %(asctime)s %(name)s '
'%(filename)s:%(lineno)d %(message)s'
), stream=sys.stdout, level=logging.DEBUG)
async def main():
bus = RedisSignalBus('redis://localhost/7')
broker = RedisBroker('redis://localhost/7')
await bus.started.send('user_agent')
user_agent = UserAgent(bus=bus, broker=broker)
comment_agent = CommentAgent(bus=bus, broker=broker)
email_agent = EmailAgent(broker=broker)
await user_agent.start()
await comment_agent.start()
await email_agent.start()
while True:
await asyncio.sleep(60)
if __name__ == '__main__':
asyncio.run(main())
Run in shell:
$ python examples/redis_server.py