✨ Toy workflow addition
This commit is contained in:
53
example_workflow/network_workflow.py
Normal file
53
example_workflow/network_workflow.py
Normal file
@ -0,0 +1,53 @@
|
||||
from time import sleep
|
||||
|
||||
from meow_base.core.runner import MeowRunner
|
||||
from meow_base.patterns.network_event_pattern import NetworkMonitor, NetworkEventPattern
|
||||
from meow_base.recipes.python_recipe import PythonRecipe, PythonHandler
|
||||
from meow_base.conductors.local_python_conductor import LocalPythonConductor
|
||||
|
||||
PORTS = [8080,8181]
|
||||
|
||||
def main():
|
||||
runners = []
|
||||
for i, port in enumerate(PORTS):
|
||||
other_port = PORTS[(i+1)%2]
|
||||
|
||||
# Gets the script ready
|
||||
script = [
|
||||
"import socket",
|
||||
"sender = socket.socket(socket.AF_INET, socket.SOCK_STREAM)",
|
||||
f"sender.connect(('127.0.0.1', {other_port}))",
|
||||
"sender.sendall(b'test')",
|
||||
"sender.close()"
|
||||
]
|
||||
|
||||
# Initialize the network monitor
|
||||
patterns = {
|
||||
"echo_pattern":NetworkEventPattern(
|
||||
"echo_pattern",
|
||||
port,
|
||||
"echo_recipe"
|
||||
)
|
||||
}
|
||||
recipes = {"echo_recipe":PythonRecipe("echo_recipe", script)}
|
||||
monitors = [NetworkMonitor(patterns, recipes)]
|
||||
|
||||
|
||||
# Initialize the handler and conductor
|
||||
handlers = [PythonHandler()]
|
||||
conductors = [LocalPythonConductor()]
|
||||
|
||||
# Start the runner
|
||||
runner = MeowRunner(monitors, handlers, conductors)
|
||||
|
||||
runner.start()
|
||||
runners.append(runner)
|
||||
|
||||
sleep(120)
|
||||
|
||||
for runner in runners:
|
||||
runner.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user