change broker to router, added debug level

This commit is contained in:
2025-03-07 16:29:09 +05:30
parent 015fbcbb15
commit 8851bdcf5f
5 changed files with 11 additions and 12 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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()

View File

@@ -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)

View File

@@ -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"}