Node example

This commit is contained in:
Eden Kirin
2023-03-20 22:00:13 +01:00
parent a0d2d1cb7f
commit 1876158d9d
21 changed files with 556 additions and 13 deletions

View File

@ -1,8 +1,13 @@
import logging
import grpc
from models import GetCurrentTimeResponse
from stubs import serve_hours_pb2
from stubs import serve_hours_pb2_grpc
from stubs import serve_currenttime_pb2
from stubs import serve_currenttime_pb2_grpc
SERVE_CURRENTTIME_HOST = "localhost"
SERVE_CURRENTTIME_PORT = 50000
SERVE_HOURS_HOST = "localhost"
SERVE_HOURS_PORT = 50001
SERVE_MINUTES_HOST = "localhost"
@ -23,10 +28,24 @@ def get_hours() -> int:
return response.hours
def get_currenttime() -> GetCurrentTimeResponse:
with grpc.insecure_channel(
f"{SERVE_CURRENTTIME_HOST}:{SERVE_CURRENTTIME_PORT}"
) as channel:
stub = serve_currenttime_pb2_grpc.ServeCurrentTimeServiceStub(channel)
raw_response = stub.GetCurrentTime(
serve_currenttime_pb2.GetCurrentTimeRequest(timezone=TIMEZONE)
)
return GetCurrentTimeResponse.from_orm(raw_response)
def run():
hours = get_hours()
print(">>>>>>>>>>>>> Hours:", hours)
currenttime = get_currenttime()
print(">>>>>>>>>>>>> CurrentTime:", currenttime)
if __name__ == "__main__":
logging.basicConfig()