Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
sysid committed Nov 30, 2019
1 parent cd8f2a1 commit 9cb1602
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 1 deletion.
57 changes: 57 additions & 0 deletions PingAgent.py
@@ -0,0 +1,57 @@
import asyncio
import logging
from pathlib import Path

import sys

sys.path.insert(0, str(Path(__file__).parent / 'munggoggo'))

from behaviour import Behaviour
from core import Core


class PingBehav(Behaviour):
async def setup(self):
print(f"Starting {self.name} . . .")
self.counter = 0

async def run(self):
self.counter += 1
msg = await self.receive()
if msg:
print(f"{self.name}: Message: {msg.body.decode()} from: {msg.app_id}, qsize: {self.queue.qsize()}") # TODO: log.warning ?!!
print(f"{self.name}: Counter: {self.counter}")
await self.publish(str(self.counter), 'ping')
await asyncio.sleep(
0.9
) # >1 triggers log messages: syncio:poll 999.294 ms took 1000.570 ms: timeout

async def teardown(self):
# print(f"Finished {self.name} with exit_code {self.exit_code}. . .")
print(f"Finished {self.name} . . .")


class Agent1(Core):

@property
def behaviour(self) -> Behaviour:
return PingBehav(self, binding_keys=['ping'])

async def setup(self) -> None:
await self.add_runtime_dependency(self.behaviour)


if __name__ == '__main__':
from mode import Worker
logging.getLogger("aio_pika").setLevel(logging.WARNING)
logging.getLogger("asyncio").setLevel(logging.INFO)

worker = Worker(
Agent1(identity='agent1'),
loglevel="info",
logfile=None,
daemon=True,
redirect_stdouts=False,
)

worker.execute_from_commandline()
3 changes: 3 additions & 0 deletions Pipfile
Expand Up @@ -12,6 +12,9 @@ rinohtype = "*"
pytest-mock = "*"
pytest-factoryboy = "*"
pytest-cov = "*"
autohooks = "*"
autohooks-plugin-black = "*"
autohooks-plugin-isort = "*"

[packages]
tw = {editable = true,path = "./../twpy"}
Expand Down
118 changes: 117 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9cb1602

Please sign in to comment.