Skip to content

Commit

Permalink
🎨 handle show request. #14
Browse files Browse the repository at this point in the history
  • Loading branch information
perillaroc committed Apr 20, 2022
1 parent e20c06c commit 1f36cee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions takler/server/network_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ async def RunAbortCommand(self, request, context):
flag=0,
message="",
)

async def RunShowRequest(self, request, context):
output = self.scheduler.handle_show_request()
return takler_pb2.ShowResponse(
output=output
)
28 changes: 28 additions & 0 deletions takler/server/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import asyncio
import time
from io import StringIO
from typing import Optional, Union
from queue import Queue, Empty


from takler.core import Bunch, Task
from takler.core.node import Node
from takler.logging import get_logger
from takler.visitor import NodeVisitor, pre_order_travel


logger = get_logger("server.scheduler")
Expand Down Expand Up @@ -71,3 +74,28 @@ def run_command_abort(self, node_path: str):
node.abort()
else:
raise ValueError(f"node must be Task: {node_path}")

def handle_show_request(self) -> str:
stream = StringIO()

class PrintVisitor(NodeVisitor):
def __init__(self):
NodeVisitor.__init__(self)
self.level = 0

def visit(self, node: Node):
place_holder = " " * self.level
node_name = node.name
node_state = node.state.node_status.name
stream.write(f"{place_holder}|- {node_name} [{node_state}]\n")

def before_visit_child(self):
self.level += 1

def after_visit_child(self):
self.level -= 1

for name, flow in self.bunch.flows.items():
pre_order_travel(flow, PrintVisitor())

return stream.getvalue()

0 comments on commit 1f36cee

Please sign in to comment.