This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.