refactor: plugin code structure

This commit is contained in:
debugtalk
2022-03-05 00:34:55 +08:00
parent 1904d404fd
commit 0ede8d7989
27 changed files with 297 additions and 25 deletions

46
plugin/python/plugin.py Normal file
View File

@@ -0,0 +1,46 @@
from concurrent import futures
import sys
import time
import grpc
import debugtalk_pb2
import debugtalk_pb2_grpc
from grpc_health.v1.health import HealthServicer
from grpc_health.v1 import health_pb2, health_pb2_grpc
class DebugTalkServicer(debugtalk_pb2_grpc.DebugTalkServicer):
"""Implementation of DebugTalk service."""
def GetNames(self, request, context):
result = debugtalk_pb2.GetNamesResponse()
return result
def Call(self, request, context):
return
def serve():
# We need to build a health service to work with go-plugin
health = HealthServicer()
health.set("plugin", health_pb2.HealthCheckResponse.ServingStatus.Value('SERVING'))
# Start the server.
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
debugtalk_pb2_grpc.add_DebugTalkServicer_to_server(DebugTalkServicer(), server)
health_pb2_grpc.add_HealthServicer_to_server(health, server)
server.add_insecure_port('127.0.0.1:1234')
server.start()
# Output information
print("1|1|tcp|127.0.0.1:1234|grpc")
sys.stdout.flush()
try:
while True:
time.sleep(60 * 60 * 24)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()