diff --git a/README.md b/README.md index d245ad7..586693f 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ Requires 3 scripts: Client, Broker and Runner Let broker's IP be `192.168.0.110` and port be `7732` ```python -from harmoney import broker as bro +from harmoney import router as rou -bro.runBroker("0.0.0.0", 7732) +ro.startRouter("0.0.0.0", 7732) ``` - Runner performs the calculations, should contain function definitions. Connects to broker using broker's IP. diff --git a/harmoney/client.py b/harmoney/client.py index d3898be..d65fc5e 100644 --- a/harmoney/client.py +++ b/harmoney/client.py @@ -37,7 +37,7 @@ class Client: return self.returnValues def _threadWorker(self, callIDX, payload): - print(callIDX, payload) + # print(callIDX, payload) ret = self.singleCall(function=payload[0], **payload[1]) self.returnValues[callIDX] = ret self.done[callIDX] =1 diff --git a/harmoney/broker.py b/harmoney/router.py similarity index 87% rename from harmoney/broker.py rename to harmoney/router.py index 7f1487c..03ff7ce 100644 --- a/harmoney/broker.py +++ b/harmoney/router.py @@ -7,9 +7,9 @@ import pickle as pkl import uuid from ._callSpec import _ClientPacket -__all__ = ["startBroker"] +__all__ = ["startRouter"] -class _Broker: +class _Router: def __init__(self, pollingDelay=0.5) -> None: self.router = fastapi.APIRouter() self.router.add_api_websocket_route("/reg", self.registerRunner) @@ -44,12 +44,11 @@ class _Broker: returnValue = self.returnDict[reqID] return returnValue -def startBroker(host, port, pollingDelay=0.1): - br = _Broker(pollingDelay=pollingDelay) +def startRouter(host, port, pollingDelay=0.1, logLevel=3): + br = _Router(pollingDelay=pollingDelay) app = fastapi.FastAPI() app.include_router(br.router) - serverConf = Config(app = app, host=host, port=port, log_level=LOG_LEVELS["warning"], ws_ping_interval=10, ws_ping_timeout=None) + level = list(LOG_LEVELS.keys())[logLevel] + serverConf = Config(app = app, host=host, port=port, log_level=LOG_LEVELS[level], ws_ping_interval=10, ws_ping_timeout=None) server = Server(config=serverConf) server.run() - -# runBroker() diff --git a/harmoney/runner.py b/harmoney/runner.py index 7ede878..2de9b77 100644 --- a/harmoney/runner.py +++ b/harmoney/runner.py @@ -18,8 +18,8 @@ async def _send(funcMap: Dict[str, Any], url): print(f"Starting Runner, ID: {id}") await w.send(base64.b64encode(pkl.dumps({"methods":list(funcMap.keys())})).decode("utf-8")) while True: - counter+=1 packetBytes=await w.recv() + counter+=1 callPk:_CallPacket = pkl.loads(packetBytes) print("-"*50 + f"\nRunning: {callPk.procedure}\nArgs: {callPk.data}\nCounter: {counter}\n" + "-"*50) funcOutput = funcMap[callPk.procedure](**callPk.data) diff --git a/pyproject.toml b/pyproject.toml index 954387d..1603c23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "harmoney" -version = "0.1.0" +version = "0.2.0" description = "Simple Remote Function Calling Framework" authors = [{name = "Phani Pavan K", email = "kphanipavan@gmail.com"}] license = {text = "AGPLv3"}