def worker_init(**kwargs): servicer.init(WorkerParams.service_name, ThreadContextHolder()) if WorkerParams.prometheus_port is not None: registry = prometheus_client.CollectorRegistry() prometheus_client.multiprocess.MultiProcessCollector(registry) prometheus_client.start_http_server(WorkerParams.prometheus_port, registry=registry)
def before_start(app, loop): SanicGrpcClientFactory.sanic_app = app grpc_client_creator = None if async_grpc_calls: grpc_client_creator = SanicGrpcClientFactory.create_grpc_client init(service_name, TaskContextHolder(loop), grpc_client_creator, **init_kwargs) SERVER_FREE_WORKERS.labels(service_name, 'sanic').set(1) apply_middlewares(app)
def init_grpc_server(service_name, workers, port, interceptors=[]): init(service_name, ThreadContextHolder()) SERVER_FREE_WORKERS.labels(service_name, 'grpc').set(workers) interceptors = interceptors + [ServerContextInterceptor()] thread_pool = futures.ThreadPoolExecutor(max_workers=workers) grpc_server = grpc.server(thread_pool, interceptors=interceptors) grpc_server.add_insecure_port(port) return grpc_server
def init_rabbitmq_server(service_name, workers, services_enum, endpoint, exchange_name='rpc', transport_options=None, retry_coordinator=RetryCoordinator(), retry_deadletter_ttl=1.0, **init_kw_args): init(service_name, ThreadContextHolder(), **init_kw_args) SERVER_FREE_WORKERS.labels(service_name, 'rabbitmq').set(workers) connection = BrokerConnection(endpoint, transport_options=transport_options) server = RabbitMQServer(workers, services_enum, exchange_name, connection, retry_coordinator, retry_deadletter_ttl=retry_deadletter_ttl) return server
def init_flask(service_name, app, **init_kwargs): init(service_name, ThreadContextHolder(), **init_kwargs) SERVER_FREE_WORKERS.labels(service_name, 'flask').set(1) apply_middlewares(app)